Cod sursa(job #3354791)

Utilizator Stefan_25Vicu Stefan Stefan_25 Data 20 mai 2026 16:34:22
Problema Reuniune Scor 90
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.23 kb
#include <fstream>
using namespace std;
ifstream cin ("reuniune.in");
ofstream cout ("reuniune.out");
struct drept {
    long long x1, y1, x2, y2;
};
drept v[5];
long long aria(drept a) {
    if (a.x1 >= a.x2 || a.y1 >= a.y2) return 0;
    return (a.x2 - a.x1) * (a.y2 - a.y1);
}
long long perim(drept a) {
    if (a.x1 >= a.x2 || a.y1 >= a.y2) return 0;
    return 2 * (a.x2 - a.x1 + a.y2 - a.y1);
}
drept inters(drept a, drept b) {
    drept r;
    r.x1 = max(a.x1, b.x1);
    r.y1 = max(a.y1, b.y1);
    r.x2 = min(a.x2, b.x2);
    r.y2 = min(a.y2, b.y2);
    return r;
}

int main() {

    cin >> v[1].x1 >> v[1].y1 >> v[1].x2 >> v[1].y2
        >> v[2].x1 >> v[2].y1 >> v[2].x2 >> v[2].y2
        >> v[3].x1 >> v[3].y1 >> v[3].x2 >> v[3].y2;

    long long A = aria(v[1]) + aria(v[2]) + aria(v[3])
        - aria(inters(v[1], v[2]))
        - aria(inters(v[1], v[3]))
        - aria(inters(v[2], v[3]))
        + aria(inters(inters(v[1], v[2]),v[3]));

    long long P = perim(v[1]) + perim(v[2]) + perim(v[3])
        - perim(inters(v[1], v[2]))
        - perim(inters(v[1], v[3]))
        - perim(inters(v[2], v[3]))
        + perim(inters(inters(v[1], v[2]),v[3]));
    cout << A << ' ' << P;

    return 0;
}