Submission #90207

#TimeUsernameProblemLanguageResultExecution timeMemory
90207nikolapesic2802Cop and Robber (BOI14_coprobber)C++14
60 / 100
1581 ms137496 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; } int convert_back(int tr) { tr%=lim; tr%=MAX_N; return tr; } vector<int> value(2*lim); vector<int> nxt(2*lim); vector<int> todo; vector<int> futuretodo; vector<int> degree(2*lim); int pos=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) { todo.pb(convert(i,j,0)); todo.pb(convert(i,j,1)); value[convert(i,j,0)]=1; value[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,1)].pb(convert(i,j,0)); degree[convert(i,j,0)]++; 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(p,j,1)].pb(convert(i,j,0)); degree[convert(i,j,0)]++; } 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,p,0)].pb(convert(i,j,1)); degree[convert(i,j,1)]++; } } } while(todo.size()) { futuretodo.clear(); /*for(auto p:todo) printf("%i ",p); printf("\n");*/ for(auto p:todo) for(auto d:graf[p]) { if(value[d]!=0) continue; if(d>=lim) { if(value[p]==1) { degree[d]--; if(degree[d]==0) { value[d]=1; futuretodo.pb(d); } } else { value[d]=-1; futuretodo.pb(d); } } else { if(value[p]==1) { value[d]=1; nxt[d]=convert_back(p); futuretodo.pb(d); } else { degree[d]--; if(degree[d]==0) { value[d]=-1; futuretodo.pb(d); } } } } todo=futuretodo; } bool t=true; for(int i=1;i<N;i++) if(value[convert(0,i,0)]!=1) t=false; if(t) return 0; return -1; } int nextMove(int R) { return pos=nxt[convert(pos,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...