답안 #944484

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
944484 2024-03-12T18:56:22 Z rainboy 토마토 (KOI13_tomato) C
16 / 16
81 ms 13584 KB
#include <stdio.h>
#include <string.h>

#define N	1000
#define M	1000
#define INF	0x3f3f3f3f

int di[] = { -1, 1, 0, 0 };
int dj[] = { 0, 0, -1, 1 };

int min(int a, int b) { return a < b ? a : b; }
int max(int a, int b) { return a > b ? a : b; }

int main() {
	static int aa[N][M], dd[N][M], qu[N * M];
	int n, m, cnt, g, h, i, i_, j, j_, ij, d;

	scanf("%d%d", &m, &n);
	for (i = 0; i < n; i++)
		for (j = 0; j < m; j++)
			scanf("%d", &aa[i][j]);
	for (i = 0; i < n; i++)
		memset(dd[i], 0x3f, m * sizeof *dd[i]);
	cnt = 0;
	for (i = 0; i < n; i++)
		for (j = 0; j < m; j++)
			if (aa[i][j] == 1)
				dd[i][j] = 0, qu[cnt++] = i * m + j;
	for (h = 0; h < cnt; h++) {
		ij = qu[h], i = ij / m, j = ij % m, d = dd[i][j] + 1;
		for (g = 0; g < 4; g++) {
			i_ = i + di[g], j_ = j + dj[g];
			if (i_ >= 0 && i_ < n && j_ >= 0 && j_ < m && aa[i_][j_] != -1 && dd[i_][j_] > d)
				dd[i_][j_] = d, qu[cnt++] = i_ * m + j_;
		}
	}
	d = 0;
	for (i = 0; i < n; i++)
		for (j = 0; j < m; j++)
			if (aa[i][j] != -1)
				d = max(d, dd[i][j]);
	if (d == INF)
		d = -1;
	printf("%d\n", d);
	return 0;
}

Compilation message

tomato.c: In function 'main':
tomato.c:18:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |  scanf("%d%d", &m, &n);
      |  ^~~~~~~~~~~~~~~~~~~~~
tomato.c:21:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |    scanf("%d", &aa[i][j]);
      |    ^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4696 KB Output is correct
3 Correct 2 ms 4444 KB Output is correct
4 Correct 1 ms 4440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4528 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4444 KB Output is correct
2 Correct 4 ms 4440 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 4 ms 8540 KB Output is correct
4 Correct 3 ms 8540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 3 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 4 ms 4700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 11612 KB Output is correct
2 Correct 16 ms 9132 KB Output is correct
3 Correct 9 ms 4956 KB Output is correct
4 Correct 9 ms 4956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 11704 KB Output is correct
2 Correct 31 ms 11600 KB Output is correct
3 Correct 7 ms 4700 KB Output is correct
4 Correct 7 ms 4780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 9564 KB Output is correct
2 Correct 58 ms 11600 KB Output is correct
3 Correct 9 ms 4988 KB Output is correct
4 Correct 38 ms 10900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 80 ms 11932 KB Output is correct
2 Correct 81 ms 12116 KB Output is correct
3 Correct 77 ms 11932 KB Output is correct
4 Correct 56 ms 13584 KB Output is correct