Submission #90184

#TimeUsernameProblemLanguageResultExecution timeMemory
90184nikolapesic2802Cop and Robber (BOI14_coprobber)C++14
0 / 100
17 ms16000 KiB
#include <bits/stdc++.h> #include "coprobber.h" using namespace std; #define pb push_back int lim=MAX_N*MAX_N; vector<vector<int> > graf(2*lim); vector<vector<int> > graph(MAX_N); int convert(int i,int j,int k) { int br=i+j*MAX_N+k*lim; return br; } vector<int> winlose(2*lim); vector<int> visited(2*lim); int dfs(int tr) { //printf("Usao za %i\n",tr); visited[tr]=1; if(winlose[tr]==1) return 1; if(tr>=lim) { for(auto p:graf[tr]) { if(visited[p]) return -1; int val=dfs(p); if(val==-1) return -1; } return 1; } else { for(auto p:graf[tr]) { if(visited[p]) continue; int val=dfs(p); if(val!=-1) return p; } return -1; } } int pozicija=0; int start(int N, bool A[MAX_N][MAX_N]) { for(int i=0;i<N;i++) for(int j=0;j<N;j++) if(A[i][j]) graph[i].pb(j); for(int i=0;i<N;i++) { for(int j=0;j<N;j++) { if(i==j) { winlose[convert(i,j,0)]=1; winlose[convert(i,j,1)]=1; continue; } //printf("%i %i %i->%i %i %i: %i->%i\n",i,j,0,i,j,1,convert(i,j,0),convert(i,j,1)); graf[convert(i,j,0)].pb(convert(i,j,1)); for(auto p:graph[i]) { //printf("%i %i %i->%i %i %i: %i->%i\n",i,j,0,p,j,1,convert(i,j,0),convert(p,j,1)); graf[convert(i,j,0)].pb(convert(p,j,1)); } for(auto p:graph[j]) { //printf("%i %i %i->%i %i %i: %i->%i\n",i,j,1,i,p,0,convert(i,j,1),convert(i,p,0)); graf[convert(i,j,1)].pb(convert(i,p,0)); } } } for(int i=1;i<N;i++) { fill(visited.begin(),visited.end(),0); if(dfs(convert(0,i,0))!=-1) return 0; } return -1; } int convert_back(int tr) { while(tr>=lim) tr-=lim; while(tr>=MAX_N) tr-=MAX_N; return tr; } int nextMove(int R) { fill(visited.begin(),visited.end(),0); for(int i=0;i<2*lim;i++) assert(visited[i]==0); return pozicija=convert_back(dfs(convert(pozicija,R,0))); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...