답안 #530369

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
530369 2022-02-25T08:38:33 Z c28dnv9q3 Nautilus (BOI19_nautilus) C++17
66 / 100
494 ms 262148 KB
#include <iostream>

using namespace std;

const int MAX_GRID = 505, MAX_M = 5005;

int r, c, m;
bool grid[MAX_GRID][MAX_GRID], visited[MAX_GRID][MAX_GRID][MAX_M], position[MAX_GRID][MAX_GRID];
string input;

void solve(int x, int y, int i) {
	if (x < 0 || x >= c || y < 0 || y >= r || !grid[y][x] || visited[y][x][i]) {
		return;
	}
	visited[y][x][i] = true;
	if (i == input.length()) {
		position[y][x] = true;
		return;
	}

	switch (input[i]) {
		case 'N':
			solve(x, y - 1, i + 1);
			break;
		case 'E':
			solve(x + 1, y, i + 1);
			break;
		case 'S':
			solve(x, y + 1, i + 1);
			break;
		case 'W':
			solve(x - 1, y, i + 1);
			break;
		case '?':
			solve(x, y - 1, i + 1);
			solve(x + 1, y, i + 1);
			solve(x, y + 1, i + 1);
			solve(x - 1, y, i + 1);
			break;
	}
}

int main() {
	cin >> r >> c >> m;

	for (int i = 0; i < r; ++i) {
		string s;
		cin >> s;
		for (int j = 0; j < c; ++j) {
			grid[i][j] = (s[j] == '.');
		}
	}

	cin >> input;

	for (int i = 0; i < r; ++i) {
		for (int j = 0; j < c; ++j) {
			solve(j, i, 0);
		}
	}

	/* bool dp[MAX_GRID][MAX_GRID][MAX_M];
	for (int i = 0; i < r; ++i) {
		for (int j = 0; j < c; ++j) {
			for (int pos = 0; pos < input.length(); ++pos) {
				if (!grid[j][i]) {
					continue;
				}
				if (pos == input.length()) {
					position[j][i] = true;
					continue;
				}

				switch (input[pos]) {
					case 'N':
						solve(i, j - 1, pos + 1);
						break;
					case 'E':
						solve(i + 1, j, pos + 1);
						break;
					case 'S':
						solve(i, j + 1, pos + 1);
						break;
					case 'W':
						solve(i - 1, j, pos + 1);
						break;
					case '?':
						solve(i, j - 1, pos + 1);
						solve(i + 1, j, pos + 1);
						solve(i, j + 1, pos + 1);
						solve(i - 1, j, pos + 1);
						break;
				}
			}
		}
	} */

	int result = 0;
	for (int i = 0; i < r; ++i) {
		for (int j = 0; j < c; ++j) {
			result += position[i][j];
		}
	}
	cout << result;
}

Compilation message

nautilus.cpp: In function 'void solve(int, int, int)':
nautilus.cpp:16:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |  if (i == input.length()) {
      |      ~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 41668 KB Output is correct
2 Correct 21 ms 32716 KB Output is correct
3 Correct 17 ms 24932 KB Output is correct
4 Correct 11 ms 17228 KB Output is correct
5 Correct 5 ms 9036 KB Output is correct
6 Correct 1 ms 588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 41668 KB Output is correct
2 Correct 21 ms 32716 KB Output is correct
3 Correct 17 ms 24932 KB Output is correct
4 Correct 11 ms 17228 KB Output is correct
5 Correct 5 ms 9036 KB Output is correct
6 Correct 1 ms 588 KB Output is correct
7 Correct 43 ms 41744 KB Output is correct
8 Correct 20 ms 25016 KB Output is correct
9 Correct 11 ms 17100 KB Output is correct
10 Correct 6 ms 9036 KB Output is correct
11 Correct 1 ms 568 KB Output is correct
12 Correct 54 ms 41752 KB Output is correct
13 Correct 42 ms 33860 KB Output is correct
14 Correct 30 ms 25164 KB Output is correct
15 Correct 6 ms 9036 KB Output is correct
16 Correct 1 ms 588 KB Output is correct
17 Correct 68 ms 41796 KB Output is correct
18 Correct 47 ms 33788 KB Output is correct
19 Correct 18 ms 17384 KB Output is correct
20 Correct 8 ms 9164 KB Output is correct
21 Correct 1 ms 588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 41668 KB Output is correct
2 Correct 21 ms 32716 KB Output is correct
3 Correct 17 ms 24932 KB Output is correct
4 Correct 11 ms 17228 KB Output is correct
5 Correct 5 ms 9036 KB Output is correct
6 Correct 1 ms 588 KB Output is correct
7 Correct 43 ms 41744 KB Output is correct
8 Correct 20 ms 25016 KB Output is correct
9 Correct 11 ms 17100 KB Output is correct
10 Correct 6 ms 9036 KB Output is correct
11 Correct 1 ms 568 KB Output is correct
12 Correct 54 ms 41752 KB Output is correct
13 Correct 42 ms 33860 KB Output is correct
14 Correct 30 ms 25164 KB Output is correct
15 Correct 6 ms 9036 KB Output is correct
16 Correct 1 ms 588 KB Output is correct
17 Correct 68 ms 41796 KB Output is correct
18 Correct 47 ms 33788 KB Output is correct
19 Correct 18 ms 17384 KB Output is correct
20 Correct 8 ms 9164 KB Output is correct
21 Correct 1 ms 588 KB Output is correct
22 Runtime error 494 ms 262148 KB Execution killed with signal 9
23 Halted 0 ms 0 KB -