Cod sursa(job #2217768)

Utilizator GiihuoTihufiNeacsu Stefan GiihuoTihufi Data 2 iulie 2018 08:46:05
Problema Reuniune Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.47 kb
#include <bits/stdc++.h>

using namespace std;

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

typedef pair<pair<int,int>,pair<int,int>> Rectangle;
vector<Rectangle> Rectangles(3);

#define X1 first.first
#define Y1 first.second
#define X2 second.first
#define Y2 second.second

Rectangle Intersect(Rectangle i,Rectangle j)
{
    if(j>i) swap(i,j);
    #define R(i) i
    int stx=R(i).X1,drx=R(i).X2;
    if(R(j).X1>R(i).X1) stx=R(j).X1;
    if(R(j).X2<R(i).X2) drx=R(j).X2;

    int sty=R(i).Y1,dry=R(i).Y2;
    if(R(j).Y1>R(i).Y1) sty=R(j).Y1;
    if(R(j).Y2<R(i).Y2) dry=R(j).Y2;
    if(stx>=drx || sty>=dry) return make_pair(make_pair(0,0),make_pair(0,0));
    else return make_pair(make_pair(stx,sty),make_pair(drx,dry));
}

uint64_t A(Rectangle R)
{    return (R.X2-R.X1)*(R.Y2-R.Y1); }
uint64_t P(Rectangle R)
{    return 2*(R.X2+R.Y2-R.X1-R.Y1); }

int main()
{
    for(int i=0,x1,y1,x2,y2;i<3;i++)
    {
        f>>x1>>y1>>x2>>y2;
        Rectangles[i]={{x1,y1},{x2,y2}};
    }
    sort(Rectangles.begin(),Rectangles.end());
    Rectangle I01 = Intersect(Rectangles[0],Rectangles[1]),
        I02 = Intersect(Rectangles[0],Rectangles[2]),
        I12 = Intersect(Rectangles[1],Rectangles[2]),
        I012 = Intersect(I01,Rectangles[2]);
    g<<A(Rectangles[0])+A(Rectangles[1])+A(Rectangles[2])-A(I01)-A(I02)-A(I12)+A(I012)<<' '
     <<P(Rectangles[0])+P(Rectangles[1])+P(Rectangles[2])-P(I01)-P(I02)-P(I12)+P(I012);
    return 0;
}