Submission #1079

#TimeUsernameProblemLanguageResultExecution timeMemory
1079tncks0121토마토 (3차원) (KOI13_tomato3D)C++98
20 / 20
165 ms21648 KiB
#include <stdio.h> FILE *in=stdin; FILE *out=stdout; int m, n, h; int map[105][105][105], cnt[105][105][105]; int q[1000050][3], f, r, chk; int x, y, z, dab; int dx[6] = {-1, 1, 0, 0, 0, 0, }; int dy[6] = {0, 0, -1, 1, 0, 0, }; int dz[6] = {0, 0, 0, 0, -1, 1, }; int main() { int i, j, l, k; fscanf(in, "%d%d%d", &m, &n, &h); for (i=0;i<=h+1;i++) { for (j=0;j<=n+1;j++) { for (l=0;l<=m+1;l++) { map[i][j][l] = -1; cnt[i][j][l] = 0; } } } f=r=0; for (i=1;i<=h;i++) { for (j=1;j<=n;j++) { for (l=1;l<=m;l++) { fscanf(in, "%d", &map[i][j][l]); if (map[i][j][l] == 1) { q[r][0]=i; q[r][1]=j; q[r][2]=l; r++; } } } } while (f<r) { x = q[f][0]; y = q[f][1]; z = q[f][2]; f++; for (k=0;k<6;k++) { if (map[x+dx[k]][y+dy[k]][z+dz[k]] == 0) { map[x+dx[k]][y+dy[k]][z+dz[k]] = 1; cnt[x+dx[k]][y+dy[k]][z+dz[k]] = cnt[x][y][z] + 1; q[r][0]=x+dx[k]; q[r][1]=y+dy[k]; q[r][2]=z+dz[k]; r++; } } } dab=0; chk = -1; for (i=1;i<=h;i++) { for (j=1;j<=n;j++) { for (l=1;l<=m;l++) { if (dab < cnt[i][j][l]) dab = cnt[i][j][l]; if (map[i][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...