# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
22505 | 크리콘 B번 문제는 그리디로 풀려요 (#40) | Young Zebra (KRIII5_YZ) | C++98 | 63 ms | 15952 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>
#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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |