# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
143315 | Sorting | Cop and Robber (BOI14_coprobber) | C++14 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "coprobber.h"
#include <bits/stdc++.h>
pair<int, short> dp[MAX_N][MAX_N][2];
bool *a;
int n;
int solve(int cop, int robber, bool turn){
pair<int, short> &p = dp[cop][robber][turn];
if(cop == robber){
if(!turn){
return cop;
}
else{
return -1;
}
}
if(dp.second == 2){
return dp.first;
}
if(dp.second == 1){
if(!turn){
return -1;
}
else{
return robber;
}
}
dp.second = 1;
dp.first = -1;
if(!turn){
for(int i = 0; i < n; i++){
if(a[i][cop] || i == cop){
int curr = solve(i, robber, !turn);
if(curr == -1){
dp.first = i;
dp.second = 2;
return dp.first;
}
}
}
}
else{
for(int i = 0; i < n; i++){
if(a[i][robber]){
int curr = solve(cop, i, !turn);
if(curr == -1){
dp.first = i;
dp.second = 2;
return dp.first;
}
}
}
}
dp.second = 2;
return dp.first;
}
int cop;
int start(int N, bool A[MAX_N][MAX_N]){
a = A;
n = N;
for(int i = 0; i < n; ++i){
for(int j = 0; j < n; ++j){
solve(i, j, 0);
}
}
int sol = -1;
for(int i = 0; i < n; i++){
bool ok = true;
for(int j = 0; j < n; j++){
if(solve(i, j, 0) == -1){
ok = false;
return;
}
}
if(ok){
sol = i;
}
}
cop = sol;
return sol;
}
int nextMove(int R){
cop = dp[cop][R][0];
return cop;
}