Cod sursa(job #3155464)

Utilizator Irina_ZZamfir Irina Irina_Z Data 8 octombrie 2023 14:27:11
Problema Reuniune Scor 60
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.38 kb
#include<bits/stdc++.h>
using namespace std;

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

struct dreptunghi
{
    long long x1, y1, x2, y2;
};

dreptunghi d1, d2, d3;

long long arietotala, perimetrutotal;

dreptunghi intersectie(dreptunghi a, dreptunghi b)
{
    dreptunghi c;
    c.x1=max(a.x1, b.x1);
    c.y1=max(a.y1, b.y1);
    c.x2=min(a.x2, b.x2);
    c.y2=min(a.y2, b.y2);
    return c;
}

long long arie(dreptunghi a)
{
    if (a.x1 > a.x2 || a.y1 > a.y2)
        return 0;
    return 1ll*(a.x2-a.x1)*(a.y2-a.y1);
}

int perimetru(dreptunghi a)
{
    if (a.x1 > a.x2 || a.y1 > a.y2)
        return 0;
    return 1ll*(2*(a.x2-a.x1 + a.y2-a.y1));
}

int main()
{
    in >> d1.x1 >> d1.y1 >> d1.x2 >> d1.y2;
    in >> d2.x1 >> d2.y1 >> d2.x2 >> d2.y2;
    in >> d3.x1 >> d3.y1 >> d3.x2 >> d3.y2;

    arietotala = arie(d1) + arie(d2) + arie(d3);
    arietotala-= (arie(intersectie(d1, d2)) + arie(intersectie(d2, d3)) + arie(intersectie(d1, d3)));
    arietotala+= arie(intersectie(intersectie(d1, d2), d3));

    perimetrutotal = perimetru(d1) + perimetru(d2) + perimetru(d3);
    perimetrutotal-= (perimetru(intersectie(d1, d2)) + perimetru(intersectie(d2, d3)) + perimetru(intersectie(d1, d3)));
    perimetrutotal+= perimetru(intersectie(intersectie(d1, d2), d3));

    out << arietotala << " " << perimetrutotal;

    return 0;
}