# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
98902 | Dullness | 토마토 (KOI13_tomato) | C11 | 166 ms | 17912 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <stdio.h>
#define MAX 1000*1000+10
int board[1005][1005];
int x1, y1, x2, y2, N, M;
int min = 99999;
int xqueue[MAX];
int yqueue[MAX];
int cntqueue[MAX];
int head, tail;
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, -1, 0, 1 };
void enqueue(int x, int y, int cnt);
void dequeue();
int point[3];
void main(){
int x, y, cnt, i, j, sum;
sum = 0; cnt = 0;
scanf("%d %d", &M, &N);
for (i = 0; i < N; i++){
for (j = 0; j < M; j++){
scanf(" %d", &board[i + 1][j + 1]);
if (board[i + 1][j + 1] == 1) enqueue(i + 1, j + 1, 0);
}
}
while (head != tail){
dequeue();
x = point[0]; y = point[1]; cnt = point[2];
for (i = 0; i < 4; i++){
if (!(x + dx[i] > 0 && x + dx[i] < (N + 1))) continue;
if (!(y + dy[i] > 0 && y + dy[i] < (M + 1))) continue;
if (board[x + dx[i]][y + dy[i]] == 1) continue;
if (board[x + dx[i]][y + dy[i]] == -1) continue;
if (board[x + dx[i]][y + dy[i]] == 0){
enqueue(x + dx[i], y + dy[i], cnt + 1);
}
}
}
min = cnt;
for (i = 0; i < N; i++){
for (j = 0; j < M; j++){
if (board[i + 1][j + 1] == 0){
min = -1; break;
}
}
}
printf("%d", min);
}
void enqueue(int x, int y, int cnt){
tail++; tail %= MAX;
xqueue[tail] = x;
yqueue[tail] = y;
cntqueue[tail] = cnt;
board[x][y] = 1;
return;
}
void dequeue(){
head++; head %= MAX;
point[0] = xqueue[head];
point[1] = yqueue[head];
point[2] = cntqueue[head];
return;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |