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<bits/stdc++.h>
#include "coprobber.h"
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define ii pair<int,int>
#define vii vector<pair<int,int> >
#define vi vector<int>
// const int MAX_N = 500 ;
struct node{
int co , ro , nw ;
} ;
bool wn[505][505][2] ;
int lft[505][505][2] , nmv[505][505][2] , visited[505][505][2] ; // [cop][rob] ; 1 = rob ; 0 = cop
int pos = -1 ;
int start(int n, bool A[MAX_N][MAX_N])
{
queue<node> q ;
for(int i=0;i<n;i++){
int cnt = 0 ;
for(int j=0;j<n;j++) cnt+= (int)A[i][j] ;
for(int j=0;j<n;j++){
lft[i][j][0] = 1 ;
lft[j][i][1] = cnt ;
}
for(int j=0;j<2;j++ ) wn[i][i][j] = 1 , q.push({i,i,j}) , lft[i][i][j] = 0 , nmv[i][i][j] = i ;
}
int r , c , tr , nxt ;
while(!q.empty()){
r = q.front().ro ; c = q.front().co ; tr = q.front().nw ; nxt = 1-tr ;
q.pop() ;
if(visited[c][r][tr]) continue ;
visited[c][r][tr] = 1 ;
if(!tr){
for(int i = 0 ;i<n;i++){
if(!A[r][i]) continue ;
if(visited[c][i][nxt]) continue ;
lft[c][i][nxt]-- ;
if(lft[c][i][nxt]) continue ;
wn[c][i][nxt] = 1 ;
q.push({c,i,nxt}) ;
}
}
else{
for(int i = 0 ;i<n;i++){
if(!A[c][i] && i!=c ) continue ;
if(visited[i][r][nxt]) continue ;
lft[i][r][nxt]-- ;
if(lft[i][r][nxt]) continue ;
wn[i][r][nxt] = 1 ;
nmv[i][r][nxt] = c ;
q.push({i,r,nxt}) ;
}
}
}
for(int i=0;i<n;i++) {
bool chk = 1 ;
for(int j=0;j<n;j++) chk = chk & wn[i][j][1] ;
if(!chk) continue ;
pos = i ;
break ;
}
return pos ;
}
int nextMove(int R)
{
return pos = nmv[pos][R][0] ;
}
# | 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... |