답안 #529678

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
529678 2022-02-23T11:29:55 Z c28dnv9q3 Nautilus (BOI19_nautilus) C++17
0 / 100
1000 ms 260 KB
#include <vector>
#include <iostream>

std::vector<int> commands;
std::vector<std::vector<char>> map;
int dp[105][105][105];

struct pos {
	int x, y;
};

bool recurse(pos p, int a) {
	if (p.x < 0 || p.y < 0 || p.x >= map.size() || p.y >= map[0].size() || map[p.x][p.y] == '#') {
		return false;
	}
	if (dp[p.x][p.y][a + 1] != 0) {
		return dp[p.x][p.y][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); break;
		case 1:p.x--; r = recurse(p, a - 1); break;
		case 2:p.y--; r = recurse(p, a - 1); break;
		case 3:p.y++; r = recurse(p, a - 1); break;
		case 4: {
			bool b = false;
			p.x++;
			b = recurse(p, a - 1)?true:b;
			p.x -= 2;
			b = recurse(p, a - 1) ? true : b;
			p.x++;
			p.y--;
			b = recurse(p, a - 1) ? true : b;
			p.y += 2;
			b = recurse(p, a - 1) ? true : b;
			p.y--;
			r = b;
		}
			  dp[p.x][p.y][a+1] = r?2:1;
			  return r;
		}
	}
}

int main() {
	int R, C, M;
	scanf("%d%d%d", &R, &C, &M);
	map = std::vector<std::vector<char>>(R);
	for (int i = 0; i < R; i++) {
		map[i].resize(C);
	}
	getchar();
	for (int i = 0; i < R; i++) {
		for (int j = 0; j < C; j++) {
			char x;
			x = getchar();
			map[i][j] = x;
		}
		getchar();
	}
	commands = std::vector<int>(M);
	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 'bool recurse(pos, int)':
nautilus.cpp:13:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |  if (p.x < 0 || p.y < 0 || p.x >= map.size() || p.y >= map[0].size() || map[p.x][p.y] == '#') {
      |                            ~~~~^~~~~~~~~~~~~
nautilus.cpp:13:53: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |  if (p.x < 0 || p.y < 0 || p.x >= map.size() || p.y >= map[0].size() || map[p.x][p.y] == '#') {
      |                                                 ~~~~^~~~~~~~~~~~~~~~
nautilus.cpp:46:1: warning: control reaches end of non-void function [-Wreturn-type]
   46 | }
      | ^
nautilus.cpp: In function 'int main()':
nautilus.cpp:50:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |  scanf("%d%d%d", &R, &C, &M);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1038 ms 260 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1038 ms 260 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1038 ms 260 KB Time limit exceeded
2 Halted 0 ms 0 KB -