Submission #483433

#TimeUsernameProblemLanguageResultExecution timeMemory
483433rainboyPatkice II (COCI21_patkice2)C11
110 / 110
229 ms51280 KiB
#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 (stderr)

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]);
      |   ^~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...