Cod sursa(job #3241917)

Utilizator divadddDavid Curca divaddd Data 5 septembrie 2024 21:48:38
Problema Balanta Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.24 kb
#include <bits/stdc++.h>
using namespace std;
const int NMAX = 1030;
int n,m;
bitset<NMAX> heavy, light;

ifstream fin("balanta.in");
ofstream fout("balanta.out");

bitset<NMAX> diff(bitset<NMAX> a, bitset<NMAX> b){
  bitset<NMAX> ans, all;
  all.set();
  ans = a & (all ^ b);
  return ans;
}

int main() {
  fin >> n >> m;
  heavy.set();
  light.set();
  heavy[0] = light[0] = 0;
  for(int i = 1; i <= m; i++){
    bitset<NMAX> lhs, rhs;
    int k, x, output;
    fin >> k;
    for(int j = 1; j <= k; j++){
      fin >> x;
      lhs[x] = 1;
    }
    for(int j = 1; j <= k; j++){
      fin >> x;
      rhs[x] = 1;
    }
    fin >> output;
    if(output == 1){ // lhs > rhs
      heavy = heavy & lhs;
      light = light & rhs;
    }else if(output == 2){ // lhs < rhs
      heavy = heavy & rhs;
      light = light & lhs;
    }else{ // lsh = rs
      heavy = diff(heavy, (rhs | lhs));
      light = diff(light, (rhs | lhs));
    }
  }
  int cnt = 0;
  for(int i = 1; i <= n; i++){
    cnt += heavy[i];
    cnt += light[i];
  }
  if(cnt == 0 || cnt > 1){
    fout << "0";
  }else{
    for(int i = 1; i <= n; i++){
      if(heavy[i] || light[i]){
        fout << i;
        break;
      }
    }
  }
  return 0;
}