Submission #69720

#TimeUsernameProblemLanguageResultExecution timeMemory
69720dooweyCop and Robber (BOI14_coprobber)C++14
100 / 100
461 ms10596 KiB
#include "coprobber.h" #include <bits/stdc++.h> using namespace std; #define MAX_N 500 struct Pos{ int cop_x; int robber_x; int next_move; /* 0 - cop * 1 - robber */ }; int dp[MAX_N][MAX_N][2]; int nex[MAX_N][MAX_N][2]; int req[MAX_N][MAX_N][2]; int deg[MAX_N]; int go; int start(int N, bool A[MAX_N][MAX_N]) { for(int i = 0;i < N;i ++ ){ for(int j = 0;j < N; j ++ ){ deg[i] += A[i][j]; } } for(int i = 0;i < MAX_N;i ++ ){ for(int j = 0;j < MAX_N;j ++ ){ nex[i][j][0] = -1; nex[i][j][1] = -1; req[i][j][1] = deg[j]; } } queue<Pos> state; for(int i = 0;i < N; i ++ ){ state.push({i, i, 0}); state.push({i, i, 1}); dp[i][i][0] = 1; dp[i][i][1] = 1; } Pos cur; int cop, robber, nx; while(!state.empty()){ cur = state.front(); cop = cur.cop_x; robber = cur.robber_x; nx = cur.next_move; state.pop(); if(nx == 1){ for(int j = 0; j < N; j ++ ){ if(A[cop][j] or cop == j){ if(dp[j][robber][0] == 0){ dp[j][robber][0] = 1; nex[j][robber][0] = cop; state.push({j, robber, 0}); } } } } else{ for(int j = 0;j < N ; j ++ ){ if(A[robber][j] and robber != j){ if(dp[cop][j][1] == 0){ req[cop][j][1] -- ; if(req[cop][j][1] == 0){ dp[cop][j][1] = 1; state.push({cop, j, 1}); } } } } } } bool ok = false; go = -1; for(int i = 0;i < N ; i ++ ){ ok = true; for(int j = 0;j < N; j ++) { if(dp[i][j][0] == 0) ok = false; } if(ok){ go = i; break; } } return go; } int nextMove(int R) { return go = nex[go][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...