Cod sursă (job #690180)

Utilizator avatar DKMKD Matei Filibiu DKMKD IP ascuns
Problemă Canibali (lot liceu) Compilator cpp-32 | 2,43 kb
Rundă vaslui_cls1112_24.01 Status evaluat
Dată 24 ian. 2023 21:40:08 Scor 100
#include <bits/stdc++.h>
#include <unordered_map>
#include <map>

using namespace std;

ifstream fin("canibali.in");
ofstream fout("canibali.out");
//-----------------------------------------
#define ll long long
#define pii pair<int, int>
#define pll pair<long long, long long>
#define vi vector<int>
#define vll vector<long long>
#define mii map<int, int>
#define si set<int>
#define sc set<char>
//-----------------------------------------
#define f(i,s,e) for(int i=s;i<=e;++i)
#define nf(i,s,e) for(i=s;i<e;++i)
#define rf(i,e,s) for(i=e;i>=s;--i)
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define sp <<" "
//------------------------------------------
const int NMAX = 1e5 + 20;
const int KMAX = 1e1 + 5;
const int MOD = 1e6 + 3;
const int INF = 0x3f3f3f3f;
//------------------------------------------
struct canibal {
    int X, Y, Z, T;
}M[NMAX];
int n, A[NMAX], B[NMAX], ct;
vector<int>g[NMAX];
bitset<NMAX>viz;
//------------------------------------------
void read() {
    fin >> n;
    for (int i = 1; i <= n; ++i)
        fin >> M[i].X >> M[i].Y >> M[i].Z >> M[i].T;
}
int connect(int nod) {
    if (viz[nod])
        return 0;
    viz[nod] = 1;
    for (int i = 0; i < g[nod].size(); i++)
        if (!B[g[nod][i]]) {
            A[nod] = g[nod][i];
            B[g[nod][i]] = nod;
            return 1;
        }
    for (int i = 0; i < g[nod].size(); i++)
        if (connect(B[g[nod][i]])) {
            A[nod] = g[nod][i];
            B[g[nod][i]] = nod;
            return 1;
        }
    return 0;
}
bool exist(int a, int b) {
    if (M[a].X < M[b].X || M[a].Y < M[b].Y || M[a].Z < M[b].Z || M[a].T < M[b].T)
        return 0;
    if (a >= b && M[a].X == M[b].X && M[a].Y == M[b].Y && M[a].Z == M[b].Z && M[a].T == M[b].T)
        return 0;
    return 1;
}
void solve() {
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= n; ++j)
            if (exist(i, j)) {
                g[i].pb(j);
                g[n + i].pb(j);
            }
    n <<= 1;
    bool ok = false;
    while (!ok) {
        ok = true;
        viz.reset();
        for (int i = 1; i <= n; ++i)
            if (!A[i] && connect(i)) {
                ct++;
                ok = false;
            }
    }
    fout << abs(ct - (n >> 1));
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    read();
    solve();
    return 0;
}