# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
22417 | 크리콘 B번 문제는 그리디로 풀려요 (#40) | Young Zebra (KRIII5_YZ) | C++98 | 46 ms | 13552 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<stdio.h>
int N, M;
char ba[555][555]; int dap[555][555];
int chk1[555][555]/*, chk2[1010][1010]*/;
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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |