#include<stdio.h>
int N, M;
char ba[555][555]; int dap[555][555];
int chk1[555][555], chk2[810][810];
int cnt, xx[4]={0,0,1,-1}, yy[4]={1,-1,0,0};
void dfs1(int x, int y, char gr, int ty, int val){
if(chk1[x][y] != ty || ba[x][y] != gr) return;
chk1[x][y]++; cnt++;
if(val) dap[x][y]=val;
for(int i=0; i<4; i++)dfs1((x+N+xx[i])%N, (y+M+yy[i])%M, gr, ty, val);
}
int err, col;
void dfs2(int x, int y, char gr){
if(x<0 || y<0 || x>=2*N || y>=2*M){
x=(x+2*N)%(2*N), y=(y+2*M)%(2*M);
if(chk2[x][y] == col) err=1;
return;
}
if(chk2[x][y] != 0 || ba[x%N][y%M] != gr) return;
chk2[x][y]=col;
for(int i=0; i<4; i++)dfs2(x+xx[i], y+yy[i], gr);
}
int main(){
scanf("%d%d\n", &N, &M);
for(int i=0; i<N; i++)gets(ba[i]);
for(int i=0; i<N; i++){
for(int j=0; j<M; j++){
if(chk1[i][j])continue;
cnt=0, dfs1(i, j, ba[i][j], 0, 0);
dfs1(i, j, ba[i][j], 1, cnt);
}
}
for(int i=0; i<2*N; i++){
for(int j=0; j<2*M; j++){
if(chk2[i][j])continue;
col++, err=0, dfs2(i, j, ba[i%N][j%M]);
if(err)dfs1(i%N, j%M, ba[i%N][j%M], 2, -1);
}
}
for(int i=0; i<N; i++){
for(int j=0; j<M; j++)printf("%d ", dap[i][j]);
puts("");
}
return 0;
}
Compilation message
YZ.cpp: In function 'int main()':
YZ.cpp:29:24: warning: 'char* gets(char*)' is deprecated [-Wdeprecated-declarations]
for(int i=0; i<N; i++)gets(ba[i]);
^
In file included from YZ.cpp:1:0:
/usr/include/stdio.h:638:14: note: declared here
extern char *gets (char *__s) __wur __attribute_deprecated__;
^
YZ.cpp:29:24: warning: 'char* gets(char*)' is deprecated [-Wdeprecated-declarations]
for(int i=0; i<N; i++)gets(ba[i]);
^
In file included from YZ.cpp:1:0:
/usr/include/stdio.h:638:14: note: declared here
extern char *gets (char *__s) __wur __attribute_deprecated__;
^
YZ.cpp:29:34: warning: 'char* gets(char*)' is deprecated [-Wdeprecated-declarations]
for(int i=0; i<N; i++)gets(ba[i]);
^
In file included from YZ.cpp:1:0:
/usr/include/stdio.h:638:14: note: declared here
extern char *gets (char *__s) __wur __attribute_deprecated__;
^
YZ.cpp:28:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d\n", &N, &M);
^
YZ.cpp:29:35: warning: ignoring return value of 'char* gets(char*)', declared with attribute warn_unused_result [-Wunused-result]
for(int i=0; i<N; i++)gets(ba[i]);
^
/tmp/ccikskK2.o: In function `main':
YZ.cpp:(.text.startup+0x4e): warning: the `gets' function is dangerous and should not be used.
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
53 ms |
11240 KB |
Output is partially correct |
2 |
Correct |
66 ms |
8904 KB |
Output is correct |
3 |
Partially correct |
53 ms |
10604 KB |
Output is partially correct |
4 |
Partially correct |
56 ms |
8408 KB |
Output is partially correct |
5 |
Correct |
53 ms |
8000 KB |
Output is correct |
6 |
Correct |
53 ms |
7128 KB |
Output is correct |
7 |
Partially correct |
56 ms |
13736 KB |
Output is partially correct |
8 |
Partially correct |
56 ms |
12092 KB |
Output is partially correct |
9 |
Partially correct |
59 ms |
12236 KB |
Output is partially correct |
10 |
Partially correct |
59 ms |
10124 KB |
Output is partially correct |
11 |
Correct |
49 ms |
13728 KB |
Output is correct |
12 |
Correct |
56 ms |
16112 KB |
Output is correct |
13 |
Partially correct |
53 ms |
11784 KB |
Output is partially correct |
14 |
Partially correct |
79 ms |
7612 KB |
Output is partially correct |
15 |
Partially correct |
66 ms |
9900 KB |
Output is partially correct |
16 |
Partially correct |
66 ms |
8692 KB |
Output is partially correct |
17 |
Correct |
73 ms |
13672 KB |
Output is correct |
18 |
Correct |
63 ms |
13668 KB |
Output is correct |
19 |
Correct |
83 ms |
6388 KB |
Output is correct |
20 |
Correct |
89 ms |
14416 KB |
Output is correct |
21 |
Partially correct |
59 ms |
12844 KB |
Output is partially correct |
22 |
Partially correct |
56 ms |
12696 KB |
Output is partially correct |
23 |
Correct |
89 ms |
11732 KB |
Output is correct |
24 |
Correct |
76 ms |
9276 KB |
Output is correct |
25 |
Partially correct |
53 ms |
9592 KB |
Output is partially correct |
26 |
Correct |
0 ms |
6388 KB |
Output is correct |
27 |
Correct |
0 ms |
6388 KB |
Output is correct |
28 |
Correct |
0 ms |
6792 KB |
Output is correct |
29 |
Correct |
0 ms |
6788 KB |
Output is correct |
30 |
Correct |
0 ms |
6388 KB |
Output is correct |
31 |
Correct |
0 ms |
6388 KB |
Output is correct |
32 |
Correct |
0 ms |
6388 KB |
Output is correct |
33 |
Correct |
0 ms |
6388 KB |
Output is correct |
34 |
Correct |
0 ms |
6388 KB |
Output is correct |
35 |
Correct |
0 ms |
6388 KB |
Output is correct |
36 |
Correct |
3 ms |
7148 KB |
Output is correct |
37 |
Correct |
6 ms |
7064 KB |
Output is correct |
38 |
Correct |
3 ms |
6388 KB |
Output is correct |
39 |
Correct |
6 ms |
7076 KB |
Output is correct |
40 |
Correct |
0 ms |
7084 KB |
Output is correct |