답안 #530140

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
530140 2022-02-24T17:08:37 Z c28dnv9q3 Nautilus (BOI19_nautilus) C++17
29 / 100
1000 ms 384 KB
#include <iostream>

using namespace std;

const int MAX = 505;

int r, c, m;
bool grid[MAX][MAX], position[MAX][MAX];
string input;

void solve(int x, int y, int i) {
	if (x < 0 || x >= c || y < 0 || y >= r || !grid[y][x]) {
		return;
	}
	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);
		}
	}

	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:15:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   15 |  if (i == input.length()) {
      |      ~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 384 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 308 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 384 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 308 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Execution timed out 1088 ms 364 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 384 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 308 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Execution timed out 1088 ms 364 KB Time limit exceeded
8 Halted 0 ms 0 KB -