답안 #98902

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
98902 2019-02-27T09:43:27 Z Dullness 토마토 (KOI13_tomato) C
0 / 16
166 ms 17912 KB
#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

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]);
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 2 ms 512 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 512 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 32 ms 640 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 7 ms 1536 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 6 ms 1056 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 3 ms 1152 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 49 ms 7068 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 74 ms 9420 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 37 ms 5724 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 166 ms 17912 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -