Submission #1067

#TimeUsernameProblemLanguageResultExecution timeMemory
1067tncks0121토마토 (KOI13_tomato)C++98
16 / 16
128 ms16792 KiB
#include <stdio.h> FILE *in=stdin; FILE *out=stdout; int m, n, h; int map[1005][1005], cnt[1005][1005], chk; int q[1000050][2], f, r; int x, y, dab; int dx[4] = {-1, 1, 0, 0,}; int dy[4] = {0, 0, -1, 1,}; int main() { int i, j, l, k; fscanf(in, "%d%d", &m, &n); for (j=0;j<=n+1;j++) { for (l=0;l<=m+1;l++) { map[j][l] = -1; cnt[j][l] = 0; } } f=r=0; for (j=1;j<=n;j++) { for (l=1;l<=m;l++) { fscanf(in, "%d", &map[j][l]); if (map[j][l] == 1) { q[r][0]=j; q[r][1]=l; r++; } } } while (f<r) { x = q[f][0]; y = q[f][1]; f++; for (k=0;k<4;k++) { if (map[x+dx[k]][y+dy[k]] == 0) { map[x+dx[k]][y+dy[k]] = 1; cnt[x+dx[k]][y+dy[k]] = cnt[x][y] + 1; q[r][0]=x+dx[k]; q[r][1]=y+dy[k]; r++; } } } dab=0; chk = 0; for (j=1;j<=n;j++) { for (l=1;l<=m;l++) { if (dab < cnt[j][l]) dab = cnt[j][l]; if (map[j][l] == 0) chk = 1; } } if (chk == 1) fprintf(out, "-1\n"); else fprintf(out, "%d\n", dab); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...