Cod sursa(job #3257490)

Utilizator Radu_BicliBiclineru Radu Radu_Bicli Data 17 noiembrie 2024 21:13:43
Problema Reuniune Scor 100
Compilator cpp-64 Status done
Runda cex_3 Marime 1.44 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin("reuniune.in");
ofstream fout("reuniune.out");
struct Dreptunghi {
    long long x0, y0, x1, y1;

    Dreptunghi(long long _x0 = 0, long long _y0 = 0, long long _x1 = 0, long long _y1 = 0) {
        x0 = _x0;
        y0 = _y0;
        x1 = _x1;
        y1 = _y1;
    }

    long long Arie() {
        return (x1 - x0) * (y1 - y0);
    }

    long long Perimetru() {
        return 2LL * ((x1 - x0) + (y1 - y0));
    }
} drept[3];

static inline Dreptunghi Intersect(Dreptunghi a, Dreptunghi b) {
    long long x0 = max(a.x0, b.x0);
    long long y0 = max(a.y0, b.y0);
    long long x1 = min(a.x1, b.x1);
    long long y1 = min(a.y1, b.y1);

    if(x0 > x1 || y0 > y1) return Dreptunghi();
    return Dreptunghi(x0, y0, x1, y1);
}

int main() {
    for(int i = 0; i < 3; i++) fin >> drept[i].x0 >> drept[i].y0 >> drept[i].x1 >> drept[i].y1;

    Dreptunghi d01 = Intersect(drept[0], drept[1]);
    Dreptunghi d12 = Intersect(drept[1], drept[2]);
    Dreptunghi d02 = Intersect(drept[0], drept[2]);
    Dreptunghi d012 = Intersect(Intersect(drept[0], drept[1]), drept[2]);

    fout << drept[0].Arie() + drept[1].Arie() + drept[2].Arie() - d01.Arie() - d12.Arie() - d02.Arie() + d012.Arie() << " ";
    fout << drept[0].Perimetru() + drept[1].Perimetru() + drept[2].Perimetru() - d01.Perimetru() - d12.Perimetru() - d02.Perimetru() + d012.Perimetru();

    return 0;
}