#include<stdio.h>
#include<memory.h>
#define mod(a,b) (((a)%(b)+(b))%b)
int N, M;
char ba[555][555]; int dap[555][555];
int chk1[555][555], xy[555][555][2];
int cnt, err, xx[4]={0,0,1,-1}, yy[4]={1,-1,0,0};
void dfs1(int x, int y, char gr, int ty, int val){
int x2=mod(x,N), y2=mod(y,M);
if(ba[x2][y2] != gr) return;
if(chk1[x2][y2] != ty){
if(xy[x2][y2][0] != x || xy[x2][y2][1] != y) err=1;
return;
}
xy[x2][y2][0]=x, xy[x2][y2][1]=y;
chk1[x2][y2]++; cnt++;
if(val) dap[x2][y2]=val;
for(int i=0; i<4; i++)dfs1(x+xx[i], y+yy[i], gr, ty, val);
}
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, err=0, dfs1(i, j, ba[i][j], 0, 0);
dfs1(i, j, ba[i][j], 1, err?-1:cnt);
}
}
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:25: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:25: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:25: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:24: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:25: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/ccCLQQqf.o: In function `main':
YZ.cpp:(.text.startup+0x4e): warning: the `gets' function is dangerous and should not be used.
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
46 ms |
11092 KB |
Output is correct |
2 |
Correct |
43 ms |
8748 KB |
Output is correct |
3 |
Correct |
36 ms |
10444 KB |
Output is correct |
4 |
Correct |
43 ms |
8252 KB |
Output is correct |
5 |
Correct |
59 ms |
7840 KB |
Output is correct |
6 |
Correct |
43 ms |
6936 KB |
Output is correct |
7 |
Correct |
63 ms |
13580 KB |
Output is correct |
8 |
Correct |
43 ms |
11932 KB |
Output is correct |
9 |
Correct |
53 ms |
12084 KB |
Output is correct |
10 |
Correct |
39 ms |
9972 KB |
Output is correct |
11 |
Correct |
49 ms |
12680 KB |
Output is correct |
12 |
Correct |
46 ms |
15952 KB |
Output is correct |
13 |
Correct |
46 ms |
11636 KB |
Output is correct |
14 |
Correct |
49 ms |
7456 KB |
Output is correct |
15 |
Correct |
63 ms |
9744 KB |
Output is correct |
16 |
Correct |
49 ms |
8544 KB |
Output is correct |
17 |
Correct |
39 ms |
11048 KB |
Output is correct |
18 |
Correct |
39 ms |
11048 KB |
Output is correct |
19 |
Correct |
56 ms |
6232 KB |
Output is correct |
20 |
Correct |
46 ms |
8728 KB |
Output is correct |
21 |
Correct |
49 ms |
12692 KB |
Output is correct |
22 |
Correct |
46 ms |
12544 KB |
Output is correct |
23 |
Correct |
59 ms |
8468 KB |
Output is correct |
24 |
Correct |
49 ms |
7540 KB |
Output is correct |
25 |
Correct |
43 ms |
9436 KB |
Output is correct |
26 |
Correct |
0 ms |
6232 KB |
Output is correct |
27 |
Correct |
0 ms |
6232 KB |
Output is correct |
28 |
Correct |
0 ms |
6284 KB |
Output is correct |
29 |
Correct |
0 ms |
6280 KB |
Output is correct |
30 |
Correct |
0 ms |
6232 KB |
Output is correct |
31 |
Correct |
0 ms |
6232 KB |
Output is correct |
32 |
Correct |
0 ms |
6232 KB |
Output is correct |
33 |
Correct |
0 ms |
6232 KB |
Output is correct |
34 |
Correct |
0 ms |
6232 KB |
Output is correct |
35 |
Correct |
0 ms |
6232 KB |
Output is correct |
36 |
Correct |
3 ms |
6540 KB |
Output is correct |
37 |
Correct |
3 ms |
6268 KB |
Output is correct |
38 |
Correct |
3 ms |
6232 KB |
Output is correct |
39 |
Correct |
0 ms |
6352 KB |
Output is correct |
40 |
Correct |
3 ms |
6556 KB |
Output is correct |