#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][j]);
if(err)dfs1(i%N, j%M, ba[i][j], 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/cctIRQ28.o: In function `main':
YZ.cpp:(.text.startup+0x4e): warning: the `gets' function is dangerous and should not be used.
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
43 ms |
11248 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |