답안 #529702

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
529702 2022-02-23T13:20:39 Z c28dnv9q3 Nautilus (BOI19_nautilus) C++17
66 / 100
30 ms 1404 KB
#include <vector>
#include <iostream>
#define MAXN 105

char commands[MAXN];
char map[MAXN][MAXN];
char dp[MAXN][MAXN][MAXN];
int R, C, M;

struct pos {
	int x, y;
};

bool recurse(pos p, int a) {
	if (p.x < 0 || p.y < 0 || p.x >= R || p.y >= C || map[p.x][p.y] == '#') {
		return false;
	}
	if (dp[p.x+1][p.y+1][a + 1] != 0) {
		return dp[p.x+1][p.y+1][a + 1] == 2;
	}
	if (a == -1) {
		return map[p.x][p.y] == '.';
	} else {
		bool r = false;
		switch (commands[a]) {
		case 0:p.x++; r = recurse(p, a - 1); p.x--; break;
		case 1:p.x--; r = recurse(p, a - 1); p.x++; break;
		case 2:p.y--; r = recurse(p, a - 1); p.y++; break;
		case 3:p.y++; r = recurse(p, a - 1); p.y--; break;
		case 4: {
			bool b = false;
			p.x++;
			b = recurse(p, a - 1) || b;
			p.x -= 2;
			b = recurse(p, a - 1) || b;
			p.x++;
			p.y--;
			b = recurse(p, a - 1) || b;
			p.y += 2;
			b = recurse(p, a - 1) || b;
			p.y--;
			r = b;
		}
		}
		dp[p.x + 1][p.y + 1][a + 1] = r ? 2 : 1;
		return r;
	}
}

int main() {
	scanf("%d%d%d", &R, &C, &M);
	getchar();
	for (int i = 0; i < R; i++) {
		for (int j = 0; j < C; j++) {
			char x;
			x = getchar();
			map[i][j] = x;
		}
		getchar();
	}
	for (int i = 0; i < M; i++) {
		char c = getchar();
		int x = -1;
		switch (c) {
		case 'N': x = 0; break;
		case 'S': x = 1; break;
		case 'E': x = 2; break;
		case 'W': x = 3; break;
		case '?': x = 4; break;
		}
		commands[i] = x;
	}

	int counter = 0;
	for (int i = 0; i < R; i++) {
		for (int j = 0; j < C; j++) {
			if (map[i][j] == '.' && recurse({ i,j },M-1)) {
				counter++;
			}
		}
	}
	std::cout << counter;
	return 0;
}

Compilation message

nautilus.cpp: In function 'int main()':
nautilus.cpp:51:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |  scanf("%d%d%d", &R, &C, &M);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 1356 KB Output is correct
2 Correct 2 ms 1356 KB Output is correct
3 Correct 2 ms 1356 KB Output is correct
4 Correct 1 ms 1356 KB Output is correct
5 Correct 1 ms 1356 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 1356 KB Output is correct
2 Correct 2 ms 1356 KB Output is correct
3 Correct 2 ms 1356 KB Output is correct
4 Correct 1 ms 1356 KB Output is correct
5 Correct 1 ms 1356 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 21 ms 1356 KB Output is correct
8 Correct 5 ms 1356 KB Output is correct
9 Correct 2 ms 1356 KB Output is correct
10 Correct 1 ms 1356 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 28 ms 1304 KB Output is correct
13 Correct 27 ms 1380 KB Output is correct
14 Correct 19 ms 1404 KB Output is correct
15 Correct 2 ms 1356 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 28 ms 1272 KB Output is correct
18 Correct 30 ms 1360 KB Output is correct
19 Correct 10 ms 1356 KB Output is correct
20 Correct 4 ms 1356 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 1356 KB Output is correct
2 Correct 2 ms 1356 KB Output is correct
3 Correct 2 ms 1356 KB Output is correct
4 Correct 1 ms 1356 KB Output is correct
5 Correct 1 ms 1356 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 21 ms 1356 KB Output is correct
8 Correct 5 ms 1356 KB Output is correct
9 Correct 2 ms 1356 KB Output is correct
10 Correct 1 ms 1356 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 28 ms 1304 KB Output is correct
13 Correct 27 ms 1380 KB Output is correct
14 Correct 19 ms 1404 KB Output is correct
15 Correct 2 ms 1356 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 28 ms 1272 KB Output is correct
18 Correct 30 ms 1360 KB Output is correct
19 Correct 10 ms 1356 KB Output is correct
20 Correct 4 ms 1356 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Runtime error 2 ms 332 KB Execution killed with signal 11
23 Halted 0 ms 0 KB -