#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[j][i][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]) 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] ;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
253 ms |
8312 KB |
Output is correct |
5 |
Correct |
42 ms |
4088 KB |
Output is correct |
6 |
Correct |
331 ms |
8388 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
352 KB |
Cop can catch the robber, but start() returned -1 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
512 KB |
Output is correct |
4 |
Incorrect |
2 ms |
384 KB |
Cop can catch the robber, but start() returned -1 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
512 KB |
Output is correct |
4 |
Correct |
246 ms |
8156 KB |
Output is correct |
5 |
Correct |
45 ms |
4216 KB |
Output is correct |
6 |
Correct |
331 ms |
8492 KB |
Output is correct |
7 |
Incorrect |
2 ms |
384 KB |
Cop can catch the robber, but start() returned -1 |
8 |
Halted |
0 ms |
0 KB |
- |