Submission #61728

#TimeUsernameProblemLanguageResultExecution timeMemory
61728tmwilliamlin168Cop and Robber (BOI14_coprobber)C++14
100 / 100
707 ms11144 KiB
#include "coprobber.h" #include <bits/stdc++.h> using namespace std; const int mxN=500; int n, as[mxN][mxN], aws[mxN][mxN], qh, qt, p, f[mxN][mxN]; bool w[mxN][mxN][2]; array<int, 3> qu[mxN*mxN*2]; int start(int n2, bool a[mxN][mxN]) { n=n2; for(int i=0; i<n; ++i) for(int j=0; j<n; ++j) for(int k=0; k<n; ++k) as[k][i]+=a[i][j]; qh=qt=0; for(int i=0; i<n; ++i) { for(int j=0; j<2; ++j) { w[i][i][j]=1; qu[qt++]={i, i, j}; } } while(qh<qt) { array<int, 3> u=qu[qh++]; for(int i=0; i<n; ++i) { if(u[2]&&(a[i][u[0]]||i==u[0])&&!w[i][u[1]][0]) { w[i][u[1]][0]=1; qu[qt++]={i, u[1], 0}; f[i][u[1]]=u[0]; } else if(!u[2]&&a[i][u[1]]&&!w[u[0]][i][1]&&++aws[u[0]][i]>=as[u[0]][i]) { w[u[0]][i][1]=1; qu[qt++]={u[0], i, 1}; } } } p=0; bool ok=1; for(int i=0; i<n&&ok; ++i) ok=w[0][i][0]; return ok?0:-1; } int nextMove(int r) { return p=f[p][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...