Cod sursa(job #3166811)

Utilizator Dragono63Stanciu Rares Stefan Dragono63 Data 9 noiembrie 2023 17:10:38
Problema Reuniune Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 2.67 kb
#ifndef LOCAL
    #pragma GCC optimize("Ofast")
#endif

#ifdef LOCAL
    #define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>
#define pb push_back
#define pii pair<int, int>
using ll = long long;
using ci = const int;
using cll = const long long;

using namespace std;

/*******************************/
// INPUT / OUTPUT

#ifndef LOCAL
    ifstream in("reuniune.in");
    ofstream out("reuniune.out");
    #define cin in
    #define cout out
#endif
/*******************************/
/// GLOBAL DECLARATIONS

ll arie, perimetru;
bool nu_se_intersecteaza;
struct Drept
{
    int x1, x2, y1, y2;

    Drept()
    {
        x1 = x2 = y1 = y2 = 0;
    }

    Drept(int _x1, int _y1, int _x2, int _y2)
    {
        x1 = _x1; y1 = _y1; x2 = _x2; y2 = _y2;
    }

    bool verif()
    {
        return (x1 <= x2 && y1 <= y2);
    }

    Drept uneste(Drept &other)
    {
        Drept res(0, 0, 0, 0);

        res.x1 = max(x1, other.x1);
        res.y1 = max(y1, other.y1);
        res.x2 = min(x2, other.x2);
        res.y2 = min(y2, other.y2);

        return res;
    }

    ll get_arie()
    {
        if (!verif())
            return 0;
        
        return 1LL * (x2 - x1) * (y2 - y1);
    }

    ll get_perimetru()
    {
        if (!verif())
            return 0;
        
        return 2LL * (x2 - x1) + 2LL * (y2 - y1);
    }

    void print()
    {
        cerr << "(" << x1 << ", " << y1 << ") cu (" << x2 << ", " << y2 << ")\n"; 
    }
} A, B, C, AB, AC, BC, ABC;
/*******************************/
/// FUNCTIONS

void ReadInput();
void Solution();
void Output();
/*******************************/
///-------------------------------------
inline void ReadInput()
{
    int x1, y1, x2, y2;

    cin >> x1 >> y1 >> x2 >> y2;
    A = Drept(x1, y1, x2, y2);

    cin >> x1 >> y1 >> x2 >> y2;
    B = Drept(x1, y1, x2, y2);

    cin >> x1 >> y1 >> x2 >> y2;
    C = Drept(x1, y1, x2, y2);
}
///-------------------------------------
inline void Solution()
{
    AB = A.uneste(B);
    AC = A.uneste(C);
    BC = B.uneste(C);
    ABC = AB.uneste(C);

    arie = A.get_arie() + B.get_arie() + C.get_arie()
           - AB.get_arie() - AC.get_arie() - BC.get_arie()
           + ABC.get_arie();

    perimetru = A.get_perimetru() + B.get_perimetru() + C.get_perimetru()
                - AB.get_perimetru() - AC.get_perimetru() - BC.get_perimetru()
                + ABC.get_perimetru(); 
}
///-------------------------------------
inline void Output()
{
    cout << arie << " " << perimetru << "\n";
}
///-------------------------------------
int main()
{
    #ifndef LOCAL
        ios::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
    #endif
    ReadInput();
    Solution();
    Output();
    return 0;
}