Cod sursă (job #570850)

Utilizator avatar lucametehau Metehau Luca Mihnea lucametehau IP ascuns
Problemă Canibali (lot liceu) Compilator cpp | 1.24 kb
Rundă Arhiva de probleme Status evaluat
Dată 10 nov. 2020 13:33:37 Scor 100
#include <bits/stdc++.h>

using namespace std;

ifstream in ("canibali.in");
ofstream out ("canibali.out");

struct S {
  int x, y, z, t;
} v[2050];

int n;

vector <int> g[4100];
bool viz[4100];
int l[4100], r[4100];

bool match(int nod) {
  viz[nod] = 1;
  for(auto &fiu : g[nod]) {
    if(!r[fiu] || (!viz[r[fiu]] && match(r[fiu]))) {
      l[nod] = fiu;
      r[fiu] = nod;
      return 1;
    }
  }
  return 0;
}

void matching() {
  bool ok = 1;
  while(ok) {
    ok = 0;
    for(int i = 1; i <= 2 * n; i++)
      viz[i] = 0;
    for(int i = 1; i <= 2 * n; i++) {
      if(!viz[i] && !l[i])
        ok |= match(i);
    }
  }
}

int main() {
  in >> n;
  for(int i = 1; i <= n; i++)
    in >> v[i].x >> v[i].y >> v[i].z >> v[i].t;
  for(int i = 1; i <= n; i++) {
    for(int j = 1; j <= n; j++) {
      if(v[i].x == v[j].x && v[i].y == v[j].y && v[i].z == v[j].z && v[i].t == v[j].t && j <= i)
        continue;
      if(v[i].x >= v[j].x && v[i].y >= v[j].y && v[i].z >= v[j].z && v[i].t >= v[j].t) {
        g[i].push_back(j);
        g[n + i].push_back(j);
      }
    }
  }
  matching();
  int ans = 0;
  for(int i = 1; i <= n; i++) {
    if(!r[i])
      ans++;
  }
  out << ans;
  return 0;
}