#include <vector>
#include <iostream>
std::vector<char> commands;
std::vector<std::vector<char>> map;
char dp[105][105][105];
struct pos {
int x, y;
};
bool recurse(pos p, int a) {
if (p.x == 2 && p.y == 0 && a == 0) {
std::cout << "hi";
}
if (dp[p.x+1][p.y+1][a + 1] != 0) {
return dp[p.x+1][p.y+1][a + 1] == 2;
}
if (p.x < 0 || p.y < 0 || p.x >= map.size() || p.y >= map[0].size() || map[p.x][p.y] == '#') {
dp[p.x + 1][p.y + 1][a + 1] = 1;
return false;
}
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)?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 + 1][p.y + 1][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<char>(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:19:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
19 | if (p.x < 0 || p.y < 0 || p.x >= map.size() || p.y >= map[0].size() || map[p.x][p.y] == '#') {
| ~~~~^~~~~~~~~~~~~
nautilus.cpp:19:53: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
19 | if (p.x < 0 || p.y < 0 || p.x >= map.size() || p.y >= map[0].size() || map[p.x][p.y] == '#') {
| ~~~~^~~~~~~~~~~~~~~~
nautilus.cpp: In function 'int main()':
nautilus.cpp:54:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
54 | scanf("%d%d%d", &R, &C, &M);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
1348 KB |
Output is correct |
2 |
Correct |
3 ms |
1316 KB |
Output is correct |
3 |
Correct |
2 ms |
1336 KB |
Output is correct |
4 |
Correct |
1 ms |
1356 KB |
Output is correct |
5 |
Correct |
1 ms |
1356 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
1348 KB |
Output is correct |
2 |
Correct |
3 ms |
1316 KB |
Output is correct |
3 |
Correct |
2 ms |
1336 KB |
Output is correct |
4 |
Correct |
1 ms |
1356 KB |
Output is correct |
5 |
Correct |
1 ms |
1356 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
25 ms |
1356 KB |
Output is correct |
8 |
Correct |
6 ms |
1484 KB |
Output is correct |
9 |
Correct |
2 ms |
1356 KB |
Output is correct |
10 |
Correct |
1 ms |
1336 KB |
Output is correct |
11 |
Correct |
1 ms |
324 KB |
Output is correct |
12 |
Incorrect |
26 ms |
1300 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
1348 KB |
Output is correct |
2 |
Correct |
3 ms |
1316 KB |
Output is correct |
3 |
Correct |
2 ms |
1336 KB |
Output is correct |
4 |
Correct |
1 ms |
1356 KB |
Output is correct |
5 |
Correct |
1 ms |
1356 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
25 ms |
1356 KB |
Output is correct |
8 |
Correct |
6 ms |
1484 KB |
Output is correct |
9 |
Correct |
2 ms |
1356 KB |
Output is correct |
10 |
Correct |
1 ms |
1336 KB |
Output is correct |
11 |
Correct |
1 ms |
324 KB |
Output is correct |
12 |
Incorrect |
26 ms |
1300 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |