Submission #90220

#TimeUsernameProblemLanguageResultExecution timeMemory
90220nikolapesic2802Cop and Robber (BOI14_coprobber)C++14
60 / 100
1589 ms239732 KiB
#include <bits/stdc++.h> #include "coprobber.h" using namespace std; #define pb push_back vector<vector<int> > graph(MAX_N); int value[MAX_N][MAX_N][2]; int nxt[MAX_N][MAX_N]; vector<array<int,3> > graf[MAX_N][MAX_N][2]; int degree[MAX_N][MAX_N][2]; vector<array<int,3> > todo; 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({i,j,0}); todo.pb({i,j,1}); value[i][j][0]=1; value[i][j][1]=1; continue; } graf[i][j][1].pb({i,j,0}); degree[i][j][0]++; for(auto p:graph[i]) { graf[p][j][1].pb({i,j,0}); degree[i][j][0]++; } for(auto p:graph[j]) { graf[i][p][0].pb({i,j,1}); degree[i][j][1]++; } } } int sz=todo.size(); //int visited[MAX_N][MAX_N][2]; //memset(visited,0,sizeof(visited)); while(todo.size()) { vector<array<int,3> > futuretodo; for(auto p:todo){ int x=p[0],y=p[1],z=p[2]; //assert(visited[x][y][z]==0); //visited[x][y][z]=1; //assert(value[x][y][z]!=0); for(auto d:graf[x][y][z]) { int i=d[0]; int j=d[1]; int k=d[2]; if(value[i][j][k]!=0) continue; if(k==1) { if(value[x][y][z]==1) { degree[i][j][k]--; if(degree[i][j][k]==0) { value[i][j][k]=1; futuretodo.pb({i,j,k}); } } else { value[i][j][k]=-1; } } else { if(value[x][y][z]==1) { value[i][j][k]=1; nxt[i][j]=x; futuretodo.pb({i,j,k}); } else { degree[i][j][k]--; if(degree[i][j][k]==0) { value[i][j][k]=-1; } } } } } todo=futuretodo; sz+=todo.size(); assert(sz<=MAX_N*MAX_N*2); } bool t=true; for(int i=1;i<N;i++) if(value[0][i][0]!=1) t=false; if(t) return 0; return -1; } int nextMove(int R) { return pos=nxt[pos][R]; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...