Submission #1928

#TimeUsernameProblemLanguageResultExecution timeMemory
19281sm2000토마토 (KOI13_tomato)C11
16 / 16
140 ms20632 KiB
#include <stdio.h> int rear=1, front=1, n, k, array[1001][1001], Queuex[1000001], Queuey[1000001], Time[1000001], Dirx[4]= {1, -1, 0, 0}, Diry[4]= {0, 0, 1, -1}, Visit[1001][1001]; void push(int a, int b, int c) { Queuex[rear] = a; Time[rear] = c; Queuey[rear++] = b; } int popx() { return Queuex[front]; } int popy() { return Queuey[front++]; } int main() { //freopen("input.txt", "r", stdin); //freopen("output.txt", "w", stdout); int s=0, i, j, check=0, m=0, res=0, checking=0, tmp=0, tle; scanf("%d %d", &n, &k); tle=n*k; tmp = n; n=k; k=tmp; for (i=1; i<=n; i++) { for (j=1; j<=k; j++) { scanf("%d", &array[i][j]); if (array[i][j] != 0) { check++; tle--; } if (array[i][j] == 1) { push(i, j, 0); Visit[i][j] = 1; } } } if (check == n*k) { printf("0"); return 0; } check=0; while (front != rear) { s=popx(); m=popy(); res++; for (i=0; i<4; i++) { if (array[s+Dirx[i]][m+Diry[i]] == 0 && s+Dirx[i] > 0 && m+Diry[i] > 0 && s+Dirx[i] <= n && m+Diry[i] <= k && Visit[s+Dirx[i]][m+Diry[i]] == 0) { tle--; array[s+Dirx[i]][m+Diry[i]] = 1; push(s+Dirx[i], m+Diry[i], Time[res]+1); Visit[s+Dirx[i]][m+Diry[i]] = 1; } } if (tle == 0) break; } for (i=1; i<=n; i++) { for (j=1; j<=k; j++) { if (array[i][j] == 1 || array[i][j] == -1) { //printf("%d ", array[i][j]); checking++; } } //printf("\n"); } if (checking == n*k) 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...