답안 #483433

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
483433 2021-10-29T12:40:43 Z rainboy Patkice II (COCI21_patkice2) C
110 / 110
229 ms 51280 KB
#include <stdio.h>

#define N	2000
#define M	2000

int di[] = { -1, 1, 0, 0 };
int dj[] = { 0, 0, -1, 1 };
char dir[] = "^v<>";

int main() {
	static char cc[N][M + 1];
	static int dd[N][M], hh[N][M], qu[N * M * 2];
	int n, m, i, j, head, cnt;

	scanf("%d%d", &n, &m);
	for (i = 0; i < n; i++)
		scanf("%s", cc[i]);
	head = n * m, cnt = 0;
	for (i = 0; i < n; i++)
		for (j = 0; j < m; j++)
			if (cc[i][j] == 'o')
				dd[i][j] = 0, qu[head + cnt++] = i * m + j;
			else
				dd[i][j] = n * m;
	while (cnt) {
		int ij, d, h;

		ij = qu[cnt--, head++], i = ij / m, j = ij % m, d = dd[i][j];
		if (cc[i][j] == 'x') {
			printf("%d\n", d);
			while (dd[i][j] > 0) {
				h = hh[i][j];
				i -= di[h], j -= dj[h], cc[i][j] = dir[h];
			}
			for (i = 0; i < n; i++)
				printf("%s\n", cc[i]);
			return 0;
		}
		for (h = 0; h < 4; h++) {
			int i_ = i + di[h], j_ = j + dj[h];

			if (i_ >= 0 && i_ < n && j_ >= 0 && j_ < m && cc[i_][j_] != 'o') {
				if (cc[i][j] == 'o' || cc[i][j] == dir[h]) {
					if (dd[i_][j_] > d)
						dd[i_][j_] = d, hh[i_][j_] = h, qu[cnt++, --head] = i_ * m + j_;
				} else {
					if (dd[i_][j_] > d + 1)
						dd[i_][j_] = d + 1, hh[i_][j_] = h, qu[head + cnt++] = i_ * m + j_;
				}
			}
		}
	}
	return 0;
}

Compilation message

Main.c: In function 'main':
Main.c:15:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |  scanf("%d%d", &n, &m);
      |  ^~~~~~~~~~~~~~~~~~~~~
Main.c:17:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |   scanf("%s", cc[i]);
      |   ^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 21 ms 10848 KB Output is correct
7 Correct 21 ms 15388 KB Output is correct
8 Correct 62 ms 23824 KB Output is correct
9 Correct 90 ms 34300 KB Output is correct
10 Correct 179 ms 45084 KB Output is correct
11 Correct 229 ms 51280 KB Output is correct