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 "grader.cpp"
#include <cstdio>
#include <queue>
#include <bitset>
#include <algorithm>
using namespace std;
int cop;
bool a[MAX_N][MAX_N];
vector<int> adjLis[MAX_N];
//sub2
int sidelength;
vector<vector<int>> solved, cnt;
vector<bitset<500>> done;
void solve(int cop, int robber, bool copturn=true){
//calling this function: robber caught
if(copturn){
if(done[cop][robber])
return;
done[cop][robber]=true;
for(int i: adjLis[robber]){
cnt[cop][i]--;
if(cnt[cop][i]==0)//no place to run
solve(cop, i, false);
}
}else{
for(int i: adjLis[cop]){
if(solved[i][robber]==-1){
solved[i][robber]=cop;
solve(i, robber, true);
}
}
if(solved[cop][robber]==-1){
solved[cop][robber]=cop;
solve(cop, robber, true);
}
}
}
int start(int n, bool A[MAX_N][MAX_N]){
for(int i=n; i--;)for(int j=n; j--;)
a[i][j]=A[i][j];
for(int i=n; i--;)for(int j=n; j--;){
if(a[i][j])
adjLis[i].push_back(j);
}
solved.assign(n, vector<int>(n, -1));
cnt.assign(n, vector<int>(n));
done.resize(n);
for(int i=n; i--;)for(int j=n; j--;)
cnt[i][j]=adjLis[j].size();
for(int i=n; i--;){
solved[i][i]=i;
solve(i, i);
}
for(int i=n; i--;)for(int j: adjLis[i]){
solved[i][j]=j;
solve(i, j);
}
if(*min_element(solved[0].begin(), solved[0].end())>=0)
return cop=0;
return -1;
}
int nextMove(int r){
return cop=solved[cop][r];
}
# | 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... |