Cod sursa(job #3245838)

Utilizator 0021592Grecu rares 0021592 Data 30 septembrie 2024 20:28:16
Problema Reuniune Scor 30
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 2.1 kb
#include <fstream>
#define int long long
using namespace std;
ifstream in("reuniune.in");
ofstream out("reuniune.out");
struct cutie
{
    int firstx, secondx, firsty, secondy;
} a[4], h;
int arie(cutie a)
{
    return (a.secondx - a.firstx) * (a.secondy - a.firsty);
}
int i, j, n, best, fuckyou;
void intersectie(cutie& a, cutie b)
{
    ///if (b.firstx > a.secondx || a.firstx > b.secondx || b.firsty > a.secondy || a.firsty > b.secondy)
    a = {max(a.firstx, b.firstx), min(a.secondx, b.secondx), max(a.firsty, b.firsty), min(a.secondy, b.secondy)};
    if (a.firstx > a.secondx || a.firsty > a.secondy)
        a = {0,0,0,0};
}
int pinex(cutie x, int ok)
{
    int best = 0;
    for (int mask = 1; mask < (1<<3); mask++)
    {
        cutie h = x;
        int nr = 0;
        for (int j = 0; j < 3; j++)
            if (mask&(1<<j))
            {
                if (j+1 == ok)
                {
                    nr = 0;
                    break;
                }
                nr++;
                intersectie(h, a[j+1]);
            }
        if (nr == 0)
            continue;
        int rsp = arie(h);
        if (nr%2 == 0)
            best -= rsp;
        else
            best += rsp;
        if (nr%2 == 0 && rsp != 0)
            fuckyou++;
    }
    return best;
}
int32_t main()
{
    a[0].firstx = a[0].firsty = -1e9;
    a[0].secondx = a[0].secondy = 1e9;
    for (i = 1; i <= 3; i++)
        in >> a[i].firstx >> a[i].firsty >> a[i].secondx >> a[i].secondy;
    out << pinex(a[0], -1);
    fuckyou = 0;
    for (i = 1; i <= 3; i++)
    {
        h = {a[i].firstx, a[i].firstx+1, a[i].firsty, a[i].secondy-1};
        best += arie(h) - pinex(h, i) + 1;
        h = {a[i].firstx, a[i].secondx-1, a[i].secondy-1, a[i].secondy};
        best += arie(h) - pinex(h, i) + 1;
        h = {a[i].secondx-1, a[i].secondx, a[i].firsty+1,a[i].secondy};
        best += arie(h) - pinex(h, i) + 1;
        h = {a[i].firstx+1, a[i].secondx, a[i].firsty, a[i].firsty+1};
        best += arie(h) - pinex(h, i) + 1;
    }
    out << ' ' << best - fuckyou;
    return 0;
}