Submission #593826

#TimeUsernameProblemLanguageResultExecution timeMemory
593826FatihSolakToy Train (IOI17_train)C++17
0 / 100
126 ms2204 KiB
#include "train.h" #include <bits/stdc++.h> #define N 15 using namespace std; int dp[(1<<N)][N]; bool edge[N][N]; bool special[N]; vector<int> adj[N]; vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v) { int n = a.size(); int m = u.size(); for(int i=0;i<m;i++){ edge[u[i]][v[i]] = 1; adj[u[i]].push_back(v[i]); } for(int i = 0;i<n;i++){ if(r[i]){ for(int mask = (1<<n)-1;mask>=0;mask--){ for(int j = 0;j<n;j++){ if(!(mask & (1<<j)))continue; if(a[j]){ dp[mask][j] = 0; for(auto u:adj[j]){ if((mask & (1<<u))){ dp[mask][j] |= (u == i); continue; } dp[mask][j] |= dp[mask + (1<<u)][u]; } } else{ dp[mask][j] = 1; for(auto u:adj[j]){ if((mask & (1<<u))){ dp[mask][j] &= (u == i); continue; } dp[mask][j] &= dp[mask + (1<<u)][u]; } } //cout << mask << " " << j << " " << dp[mask][j] << endl; } } special[i] = dp[(1<<i)][i]; //cout << i << " " << special[i] << endl; } } vector<int> res(n); for(int i = 0; i < n; i++){ for(int mask = (1<<n)-1;mask>=0;mask--){ bool x = 0; for(int c = 0;c<n;c++){ if(mask & (1<<c)) x |= special[c]; } for(int j = 0;j<n;j++){ if(!(mask & (1<<j)))continue; dp[mask][j] = 0; if(a[j]){ for(auto u:adj[j]){ if((mask & (1<<u))){ continue; } dp[mask][j] |= dp[mask + (1<<u)][u]; } } else{ dp[mask][j] = 1; for(auto u:adj[j]){ if((mask & (1<<u))){ dp[mask][j] = 0; continue; } dp[mask][j] &= dp[mask + (1<<u)][u]; } } dp[mask][j] |= x; } } res[i] = dp[(1<<i)][i]; } return res; }
#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...