#include "sungjin.h"
static int N, M, ba[1010][1010], chk[1010][1010], xx[4]={1,-1,0,0}, yy[4]={0,0,1,-1}; // DURL
static void dfs1(int x, int y){
if(x<0 || y<0 || x>N+1 || y>M+1) return;
if(chk[x][y]) return;
chk[x][y]=-1;
for(int i=0; i<4; i++){
if(ba[x][y]&(1<<i)) continue;
dfs1(x+xx[i], y+yy[i]);
}
}
static int col;
static void dfs2(int x, int y){
if(x<=0 || y<=0 || x>N || y>M) return;
if(chk[x][y]) return;
chk[x][y]=col;
for(int i=0; i<4; i++) dfs2(x+xx[i], y+yy[i]);
}
void Init(int N_, int M_, int W, int R[], int C[], int dir[]) {
N=N_, M=M_;
for(int i=W; i--;){
if(dir[i]==1) ba[R[i]][C[i]+1] |= 1<<3;
if(dir[i]==2) ba[R[i]][C[i]-1] |= 1<<2;
if(dir[i]==3) ba[R[i]+1][C[i]] |= 1<<1;
if(dir[i]==4) ba[R[i]-1][C[i]] |= 1<<0;
}
dfs1(0,0);
for(int i=1; i<=N; i++){
for(int j=1; j<=M; j++){
if(chk[i][j]) continue;
++col; dfs2(i,j);
}
}
}
int WereSameTerritory(int R1, int C1, int R2, int C2) {
if(chk[R1][C1]<0 || chk[R2][C2]<0) return 0;
return chk[R1][C1] == chk[R2][C2];
}
#include "dowoon.h"
static int N, M, ba[1010][1010], my, no, xx[4]={1,-1,0,0}, yy[4]={0,0,1,-1};
static void dfs(int x, int y, int hx, int hy){
if(x<=0 || y<=0 || x>N || y>M) return;
if(ba[x][y]) return;
if(Ask(x,y,hx,hy)) ba[x][y]=1, my++;
else{ ba[x][y]=-1; no++; return; }
for(int i=0; i<4; i++) dfs(x+xx[i], y+yy[i], hx, hy);
}
int Guess(int N_, int M_) {
N=N_, M=M_;
for(int j=1; j<M; j++){
for(int i=1; i<=N; i++){
if(2*no >= N*M) return 0;
if(ba[i][j] || ba[i][j+1]) continue;
int st=i, k, fl=0;
for(k=st; k<=N; k++){
if(ba[k][j] || ba[k][j+1]) break;
int a = Ask(k,j,k,j+1);
if(a){ fl=1; break; }
}
if(!fl){
i=k-1;
while(--k >= st) ba[k][j]=-1, no++;
continue;
}
ba[k][j]=ba[k][j+1]=1; my=2;
for(int k2=k-1; k2>=st; k2--){
int a = Ask(k2,j,k2+1,j);
if(a) ba[k2][j]=1, ba[k2][j+1]=-1, my++, no++;
else{
ba[k2][j]=-1, no++;
while(--k2 >= st) ba[k2][j]=-1, no++;
break;
}
}
dfs(k+1, j, k, j);
dfs(k+1, j+1, k, j);
dfs(k, j+2, k, j);
dfs(k-1, j+1, k, j);
if(my*2 > N*M) return 1;
no+=my, my=0;
i=k-1;
}
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
752 KB |
Correct |
2 |
Correct |
6 ms |
824 KB |
Correct |
3 |
Correct |
18 ms |
1460 KB |
Correct |
4 |
Correct |
83 ms |
16456 KB |
Correct |
5 |
Correct |
78 ms |
16456 KB |
Correct |
6 |
Correct |
299 ms |
68652 KB |
Correct |
7 |
Correct |
314 ms |
96872 KB |
Correct |
8 |
Correct |
323 ms |
142084 KB |
Correct |
9 |
Correct |
263 ms |
176968 KB |
Correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
752 KB |
Correct |
2 |
Correct |
6 ms |
824 KB |
Correct |
3 |
Correct |
18 ms |
1460 KB |
Correct |
4 |
Correct |
83 ms |
16456 KB |
Correct |
5 |
Correct |
78 ms |
16456 KB |
Correct |
6 |
Correct |
299 ms |
68652 KB |
Correct |
7 |
Correct |
314 ms |
96872 KB |
Correct |
8 |
Correct |
323 ms |
142084 KB |
Correct |
9 |
Correct |
263 ms |
176968 KB |
Correct |
10 |
Correct |
748 ms |
176968 KB |
Correct |
11 |
Correct |
61 ms |
176968 KB |
Correct |
12 |
Correct |
27 ms |
176968 KB |
Correct |
13 |
Correct |
8 ms |
176968 KB |
Correct |
14 |
Correct |
4 ms |
176968 KB |
Correct |
15 |
Correct |
6 ms |
176968 KB |
Correct |
16 |
Correct |
4 ms |
176968 KB |
Correct |
17 |
Correct |
4 ms |
176968 KB |
Correct |
18 |
Correct |
4 ms |
176968 KB |
Correct |
19 |
Correct |
1216 ms |
177604 KB |
Correct |
20 |
Correct |
7 ms |
178240 KB |
Correct |
21 |
Correct |
5 ms |
178240 KB |
Correct |
22 |
Correct |
5 ms |
178240 KB |
Correct |
23 |
Correct |
6 ms |
178240 KB |
Correct |
24 |
Correct |
22 ms |
178240 KB |
Correct |
25 |
Correct |
11 ms |
178240 KB |
Correct |
26 |
Correct |
26 ms |
178240 KB |
Correct |
27 |
Correct |
75 ms |
178240 KB |
Correct |
28 |
Correct |
60 ms |
178240 KB |
Correct |
29 |
Correct |
78 ms |
178240 KB |
Correct |
30 |
Correct |
95 ms |
178240 KB |
Correct |
31 |
Correct |
326 ms |
178240 KB |
Correct |
32 |
Correct |
302 ms |
178240 KB |
Correct |
33 |
Correct |
350 ms |
178240 KB |
Correct |
34 |
Correct |
354 ms |
178240 KB |
Correct |
35 |
Correct |
372 ms |
178240 KB |
Correct |
36 |
Correct |
368 ms |
178240 KB |
Correct |
37 |
Correct |
334 ms |
178240 KB |
Correct |
38 |
Correct |
355 ms |
178240 KB |
Correct |
39 |
Correct |
254 ms |
178240 KB |
Correct |
40 |
Correct |
251 ms |
178240 KB |
Correct |
41 |
Correct |
316 ms |
178240 KB |
Correct |
42 |
Correct |
358 ms |
178240 KB |
Correct |
43 |
Correct |
428 ms |
178240 KB |
Correct |
44 |
Correct |
165 ms |
178240 KB |
Correct |
45 |
Correct |
137 ms |
178240 KB |
Correct |
46 |
Correct |
351 ms |
178240 KB |
Correct |