Submission #795907

#TimeUsernameProblemLanguageResultExecution timeMemory
795907rainboy토마토 (3차원) (KOI13_tomato3D)C11
20 / 20
93 ms13692 KiB
#include <stdio.h> #define N1 100 #define N2 100 #define N3 100 int max(int a, int b) { return a > b ? a : b; } int main() { static int aa[N1][N2][N3], dd[N1][N2][N3], qu[N1 * N2 * N3]; int n1, n2, n3, cnt, h, i1, i2, i3, u, d, d_; scanf("%d%d%d", &n3, &n2, &n1); for (i1 = 0; i1 < n1; i1++) for (i2 = 0; i2 < n2; i2++) for (i3 = 0; i3 < n3; i3++) scanf("%d", &aa[i1][i2][i3]); cnt = 0; for (i1 = 0; i1 < n1; i1++) for (i2 = 0; i2 < n2; i2++) for (i3 = 0; i3 < n3; i3++) if (aa[i1][i2][i3] == 1) dd[i1][i2][i3] = 0, qu[cnt++] = (i1 * n2 + i2) * n3 + i3; else dd[i1][i2][i3] = n1 * n2 * n3; for (h = 0; h < cnt; h++) { u = qu[h], i1 = u / n3 / n2, i2 = u / n3 % n2, i3 = u % n3, d = dd[i1][i2][i3] + 1; if (i1 > 0 && aa[i1 - 1][i2][i3] != -1 && dd[i1 - 1][i2][i3] > d) dd[i1 - 1][i2][i3] = d, qu[cnt++] = ((i1 - 1) * n2 + i2) * n3 + i3; if (i1 + 1 < n1 && aa[i1 + 1][i2][i3] != -1 && dd[i1 + 1][i2][i3] > d) dd[i1 + 1][i2][i3] = d, qu[cnt++] = ((i1 + 1) * n2 + i2) * n3 + i3; if (i2 > 0 && aa[i1][i2 - 1][i3] != -1 && dd[i1][i2 - 1][i3] > d) dd[i1][i2 - 1][i3] = d, qu[cnt++] = (i1 * n2 + (i2 - 1)) * n3 + i3; if (i2 + 1 < n2 && aa[i1][i2 + 1][i3] != -1 && dd[i1][i2 + 1][i3] > d) dd[i1][i2 + 1][i3] = d, qu[cnt++] = (i1 * n2 + (i2 + 1)) * n3 + i3; if (i3 > 0 && aa[i1][i2][i3 - 1] != -1 && dd[i1][i2][i3 - 1] > d) dd[i1][i2][i3 - 1] = d, qu[cnt++] = (i1 * n2 + i2) * n3 + (i3 - 1); if (i3 + 1 < n3 && aa[i1][i2][i3 + 1] != -1 && dd[i1][i2][i3 + 1] > d) dd[i1][i2][i3 + 1] = d, qu[cnt++] = (i1 * n2 + i2) * n3 + (i3 + 1); } d_ = 0; for (i1 = 0; i1 < n1; i1++) for (i2 = 0; i2 < n2; i2++) for (i3 = 0; i3 < n3; i3++) if (aa[i1][i2][i3] == 0) d_ = max(d_, dd[i1][i2][i3]); printf("%d\n", d_ == n1 * n2 * n3 ? -1 : d_); return 0; }

Compilation message (stderr)

cc.c: In function 'main':
cc.c:13:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |  scanf("%d%d%d", &n3, &n2, &n1);
      |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc.c:17:5: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |     scanf("%d", &aa[i1][i2][i3]);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...