이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "coprobber.h"
#include <bits/stdc++.h>
using namespace std;
pair<int, short> dp[MAX_N][MAX_N][2];
bool a[MAX_N][MAX_N];
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(p.second >= 1){
return p.first;
}
if(p.second == 1){
if(!turn){
return -1;
}
else{
return robber;
}
}
p.second = 1;
p.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){
p.first = i;
p.second = 2;
return p.first;
}
}
}
}
else{
for(int i = 0; i < n; ++i){
if(a[i][robber]){
int curr = solve(cop, i, !turn);
if(curr == -1){
p.first = i;
p.second = 2;
return p.first;
}
}
}
}
p.second = 2;
return p.first;
}
int cop;
int start(int N, bool A[MAX_N][MAX_N]){
n = N;
for(int i = 0; i < n; ++i){
for(int j = 0; j < n; ++j){
a[i][j] = A[i][j];
}
}
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;
break;
}
}
if(ok){
sol = i;
}
}
cop = sol;
return sol;
}
int nextMove(int R){
//cout << cop << " - " << R << endl;
cop = dp[cop][R][0].first;
//cout << cop << " -> " << R << endl << endl;
return cop;
}
/*
g++ "Baltic 14-coprobber.cpp" grader.cpp -std=c++11 -O2 -static -Wall -o coprobber
*/
/*
3
0 1 0
1 0 1
0 1 0
1
1 2 1 2
2 0 0 2
1 0 0 2
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |