Submission #612633

#TimeUsernameProblemLanguageResultExecution timeMemory
612633MohamedAliSaidaneToy Train (IOI17_train)C++14
22 / 100
2095 ms2004 KiB
#include <bits/stdc++.h> //#include "train.h" using namespace std; typedef long long ll; typedef double ld; typedef pair<int,int> pii; typedef pair<ll,ll> pll; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pii> vpi; typedef vector<pll> vpl; #define pb push_back #define popb pop_back #define all(x) (x).begin(),(x).end() #define ff first #define ss second const int nax = 5004; const int MOD = 1e9 + 7; int n, m ; vi adj[nax], rev_adj[nax]; int siz[nax]; set<int> cur; int cnt[nax]; int A[nax]; void rec(int x) { if(cur.count(x) != 0) return ; cur.insert(x); for(auto e: rev_adj[x]) { cnt[e]++; if(cnt[e] == siz[e]) rec(e); else if(A[e]) rec(e); } } vi who_wins(vi a, vi r, vi u, vi v) { n = a.size(); m = u.size(); for(int i= 0 ; i < n; i++) A[i] = a[i]; for(int i= 0; i < m; i ++) { adj[u[i]].pb(v[i]); rev_adj[v[i]].pb(u[i]); } for(int i = 0 ; i < n; i ++ ) siz[i] = (int)(adj[i].size()); vi ans(n, 0); vi chrg; for(int i= 0 ; i < n;i ++) if(r[i]) chrg.pb(i); int sz = chrg.size(); if(sz == 0) return ans; for(int mask = 1; mask < (1 << sz); mask ++) { vi org; for(int i= 0; i < sz; i ++) if((1 << i) & mask) org.pb(chrg[i]); cur.clear(); for(int i= 0 ; i < n;i ++) cnt[i] = 0 ; for(auto e: org) { rec(e); } bool flag= true; for(auto e: org) { if(a[e]) { if(cnt[e] == 0) flag = false; } if(!a[e] && (cnt[e] != siz[e])) flag = false; } if(flag) { for(auto e: cur) ans[e] = 1; } } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...