Cod sursa(job #3264184)

Utilizator Barbu_MateiBarbu Matei Barbu_Matei Data 18 decembrie 2024 20:33:38
Problema Reuniune Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.5 kb
#include <bits/stdc++.h>
using namespace std;

struct point {
    int x1, y1, x2, y2;
} v[4];

point intersect(point a, point b) {
    return {max(a.x1, b.x1), max(a.y1, b.y1), min(a.x2, b.x2), min(a.y2, b.y2)};
}

int main() {
    //ifstream cin("reuniune.in");
    //ofstream cout("reuniune.out");
    for (int i = 1; i <= 3; ++i) {
        cin >> v[i].x1 >> v[i].y1 >> v[i].x2 >> v[i].y2;
    }
    long long arie = 0, perim = 0;
    for (int i = 1; i <= (1 << 3) - 1; ++i) {
        vector<int> k;
        for (int j = 0; j < 3; ++j) {
            if (i >> j & 1) {
                k.push_back(j + 1);
            }
        }
        point res = {INT_MIN, INT_MIN, INT_MAX, INT_MAX};
        bool ok = true;
        for (auto i : k) {
            res = intersect(res, v[i]);
            if (res.x1 > res.x2 || res.y1 > res.y2) {
                ok = false;
                break;
            }
        }
        if (ok && k.size() % 2 == 0) {
            //cout << "-";
            arie -= 1ll * abs(res.x2 - res.x1) * abs(res.y2 - res.y1);
            perim -= 2ll * abs(res.x2 - res.x1) + 2 * abs(res.y2 - res.y1);

        } else if (ok) {
            cout << "+";
            arie += 1ll * abs(res.x2 - res.x1) * abs(res.y2 - res.y1);
            perim += 2ll * abs(res.x2 - res.x1) + 2 * abs(res.y2 - res.y1);
        }

        if (ok) {
            cout << res.x1 << " " << res.y1 << " " << res.x2 << " " << res.y2 << "\n";
        }

    }
    cout << arie << " " << perim;
}