Cod sursa(job #3125921)

Utilizator andreiiorgulescuandrei iorgulescu andreiiorgulescu Data 4 mai 2023 19:35:17
Problema Reuniune Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.28 kb
#include <bits/stdc++.h>

using namespace std;

ifstream in("reuniune.in");
ofstream out("reuniune.out");

#define int long long

struct dreptunghi
{
    int x0,y0,x1,y1;
};

dreptunghi d1,d2,d3;

dreptunghi inters(dreptunghi a,dreptunghi b)
{
    dreptunghi c;
    c.x0 = max(a.x0,b.x0);
    c.y0 = max(a.y0,b.y0);
    c.x1 = min(a.x1,b.x1);
    c.y1 = min(a.y1,b.y1);
    return c;
}

int aria(dreptunghi a)
{
    if (a.x0 > a.x1 or a.y0 > a.y1)
        return 0;
    return (a.x1 - a.x0) * (a.y1 - a.y0);
}

int perimetru(dreptunghi a)
{
    if (a.x0 > a.x1 or a.y0 > a.y1)
        return 0;
    return 2 * (a.x1 - a.x0 + a.y1 - a.y0);
}

signed main()
{
    in >> d1.x0 >> d1.y0 >> d1.x1 >> d1.y1;
    in >> d2.x0 >> d2.y0 >> d2.x1 >> d2.y1;
    in >> d3.x0 >> d3.y0 >> d3.x1 >> d3.y1;
    int atot = 0,ptot = 0;
    atot = aria(d1) + aria(d2) + aria(d3);
    //cout << atot;
    ptot = perimetru(d1) + perimetru(d2) + perimetru(d3);
    atot -= (aria(inters(d1,d2)) + aria(inters(d1,d3)) + aria(inters(d2,d3)));
    ptot -= (perimetru(inters(d1,d2)) + perimetru(inters(d1,d3)) + perimetru(inters(d2,d3)));
    atot += aria(inters(d1,inters(d2,d3)));
    ptot += perimetru(inters(d1,inters(d2,d3)));
    out << atot << ' ' << ptot;
    return 0;
}