Cod sursa(job #3264181)

Utilizator Barbu_MateiBarbu Matei Barbu_Matei Data 18 decembrie 2024 20:01:37
Problema Reuniune Scor 20
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.6 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");
    point limit;
    for (int i = 1; i <= 3; ++i) {
        cin >> v[i].x1 >> v[i].y1 >> v[i].x2 >> v[i].y2;
        limit.x1 = min(limit.x1, v[i].x1);
        limit.y1 = min(limit.y1, v[i].y1);
        limit.x2 = max(limit.x2, v[i].x2);
        limit.y2 = max (limit.y2, v[i].y2);
    }
    long long arie = 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 -= abs(res.x2 - res.x1) * abs(res.y2 - res.y1);
        } else if (ok) {
            //cout << "+";
            arie += abs(res.x2 - res.x1) * abs(res.y2 - res.y1);
        }

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

    }
    long long perim = 2ll * abs(limit.x2 - limit.x1) + 2 * abs(limit.y2 - limit.y1);
    cout << arie << " " << perim;
}