Submission #837963

#TimeUsernameProblemLanguageResultExecution timeMemory
837963boyliguanhanCop and Robber (BOI14_coprobber)C++17
100 / 100
267 ms6604 KiB
#include "coprobber.h" #include<vector> #define NN 500 #pragma GCC optimize(2) int ok[NN][NN][2], nxt[NN][NN], vis[NN][NN][2], sz[NN][NN]; bool a[NN][NN]; std::vector<int> adj[NN]; int pos; void dfs(int x, int y, int who) { ok[x][y][who] = 1; if (who == 1) { for (auto i : adj[x]) if (!ok[i][y][0]) nxt[i][y] = x,dfs(i, y, 0); if (!ok[x][y][0]) nxt[x][y] = x,dfs(x, y, 0); } else for (auto i : adj[y]) if (!--sz[x][i] && !ok[x][i][1]) dfs(x, i, 1); } int start(int N, bool A[NN][NN]) { for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) if (A[i][j]) adj[i].push_back(j); for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) sz[i][j] = adj[j].size(); for (int i = 0; i < N; i++) { if (!ok[i][i][0]) dfs(i, i , 0); if (!ok[i][i][1]) dfs(i, i, 1); } for (pos = 0; pos < N; pos++) { bool still = 1; for (int i = 0; i < N; i++) if (!ok[pos][i][0]) still = 0; if (still) return pos; } 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...