Submission #1925

#TimeUsernameProblemLanguageResultExecution timeMemory
19251sm2000토마토 (3차원) (KOI13_tomato3D)C11
12 / 20
144 ms24616 KiB
#include <stdio.h> int Queuex[500001], Queuey[500001], Queuez[500001], Time[500001], check=0, checking=0; int front=1, rear=1, tomato[101][201][101], visit[101][201][101]; int Dirx[8]={0, -1, 1, 0, 0, 0, 0}, Diry[8]={0, 0, 0, -1, 1, 0, 0}, Dirz[8]={0, 0, 0, 0, 0, -1, 1}; void push(int a, int b, int c, int t) { Queuex[rear] = a; Queuey[rear] = b; Queuez[rear] = c; Time[rear] = t; rear++; } int Qx() { return Queuex[front]; } int Qy() { return Queuey[front]; } int Qz() { return Queuez[front++]; } int main() { //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); int n, k, l, tle=0, res=0, tmp=0; int i, j, a; int x1=0, x2=0, x3=0; scanf("%d %d %d", &n, &k, &l); tle=n*k*l; tmp = n; n = k; k = tmp; for (i=1; i<=l; i++) { for (j=1; j<=n; j++) { for (a=1; a<=k; a++) { scanf("%d", &tomato[i][j][a]); if (tomato[i][j][a] != 0) { check++; tle--; } if (tomato[i][j][a] == 1) { push(i, j, a, 0); visit[i][j][a] = 1; } } } } while (front != rear) { x1=Qx(); x2=Qy(); x3=Qz(); res++; for (i=1; i<=6; i++) { if (tomato[x1+Dirx[i]][x2+Diry[i]][x3+Dirz[i]] == 0 && visit[x1+Dirx[i]][x2+Diry[i]][x3+Dirz[i]] == 0 && x1+Dirx[i] > 0 && x1+Dirx[i] <= l && x2+Diry[i] > 0 && x2+Diry[i] <= n && x3+Dirz[i] > 0 && x3+Dirz[i] <= k) { tle--; tomato[x1+Dirx[i]][x2+Diry[i]][x3+Dirz[i]] = 1; push(x1+Dirx[i], x2+Diry[i], x3+Dirz[i], Time[res]+1); visit[x1+Dirx[i]][x2+Diry[i]][x3+Dirz[i]] = 1; } } if (tle == 0) break; } for (i=1; i<=l; i++) { for (j=1; j<=n; j++) { for (a=1; a<=k; a++) { if (tomato[i][j][a] == -1 || tomato[i][j][a] == 1) { checking++; } } } } if (n*k*l == checking) printf("%d", Time[rear-1]); else printf("-1"); 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...