Cod sursa(job #1364775)

Utilizator Theodor1000Cristea Theodor Stefan Theodor1000 Data 27 februarie 2015 20:12:33
Problema Reuniune Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 2.05 kb
#include <cstdio>
#include <algorithm>

using namespace std;

int c[4][8];

inline long long surface (int a, int b)
{
    int x = min (c[a][4], c[b][4]) - max (c[a][2], c[b][2]);
    int y = min (c[a][3], c[b][3]) - max (c[a][1], c[b][1]);

    if (x < 0 || y < 0) return 0;
    else return 1LL * x * y;
}

inline long long per (int a, int b)
{
    int x = min (c[a][4], c[b][4]) - max (c[a][2], c[b][2]);
    int y = min (c[a][3], c[b][3]) - max (c[a][1], c[b][1]);

    if (x < 0 || y < 0) return 0;
    else return 2LL * (1LL * x + 1LL * y);
}

int main ()
{
    freopen ("reuniune.in", "r", stdin);
    freopen ("reuniune.out", "w", stdout);

    for (int i = 1; i <= 3; ++i)
        for (int j = 1; j <= 4; ++j)
            scanf ("%d", &c[i][j]);

    long long s1 = 1LL * (c[1][3] - c[1][1]) * (c[1][4] - c[1][2]);
    long long s2 = 1LL * (c[2][3] - c[2][1]) * (c[2][4] - c[2][2]);
    long long s3 = 1LL * (c[3][3] - c[3][1]) * (c[3][4] - c[3][2]);

    long long s12 = surface (1, 2);
    long long s23 = surface (2, 3);
    long long s13 = surface (1, 3);

    int x = min (min (c[1][4], c[2][4]), c[3][4]) - max (max (c[1][2], c[2][2]), c[3][2]);
    int y = min (min (c[1][3], c[2][3]), c[3][3]) - max (max (c[1][1], c[2][1]), c[3][1]);

    long long s123 = 0LL;
    if (x > 0 && y > 0) s123 = 1LL * x * y;

    s12 = s1 + s2 + s3 - s12 - s23 - s13 + s123;
    printf ("%lld ", s12);

    s1 = 2LL * (1LL * (c[1][3] - c[1][1]) + 1LL * (c[1][4] - c[1][2]));
    s2 = 2LL * (1LL * (c[2][3] - c[2][1]) + 1LL * (c[2][4] - c[2][2]));
    s3 = 2LL * (1LL * (c[3][3] - c[3][1]) + 1LL * (c[3][4] - c[3][2]));

    s12 = per (1, 2);
    s23 = per (2, 3);
    s13 = per (1, 3);

    x = min (min (c[1][4], c[2][4]), c[3][4]) - max (max (c[1][2], c[2][2]), c[3][2]);
    y = min (min (c[1][3], c[2][3]), c[3][3]) - max (max (c[1][1], c[2][1]), c[3][1]);

    s123 = 0LL;
    if (x > 0 && y > 0) s123 = 2LL * (1LL * x + 1LL * y);

    s12 = s1 + s2 + s3 - s12 - s23 - s13 + s123;
    printf ("%lld\n", s12);

    return 0;
}