Submission #98902

#TimeUsernameProblemLanguageResultExecution timeMemory
98902Dullness토마토 (KOI13_tomato)C11
0 / 16
166 ms17912 KiB
#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)

tomato.c:5:9: warning: built-in function 'y1' declared as non-function
 int x1, y1, x2, y2, N, M;
         ^~
tomato.c:17:6: warning: return type of 'main' is not 'int' [-Wmain]
 void main(){
      ^~~~
tomato.c: In function 'main':
tomato.c:19:23: warning: variable 'sum' set but not used [-Wunused-but-set-variable]
  int x, y, cnt, i, j, sum;
                       ^~~
tomato.c:21:2: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &M, &N);
  ^~~~~~~~~~~~~~~~~~~~~~
tomato.c:24:4: warning: ignoring return value of 'scanf', declared with attribute warn_unused_result [-Wunused-result]
    scanf(" %d", &board[i + 1][j + 1]);
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...