This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
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()) {
| ~~^~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |