#include <bits/stdc++.h>
using namespace std;
bool been[102][102][102];
bool lastpos[502][502];
string dirs;
vector<vector<bool>> field;
void dfs(int n, int x, int y)
{
if (been[n][x][y])
return;
if (!field[y][x])
return;
if (n == dirs.size())
{
lastpos[y][x] = true;
return;
}
been[n][x][y] = true;
if (dirs[n] == 'N')
dfs(n + 1, x, y - 1);
else if (dirs[n] == 'S')
dfs(n + 1, x, y + 1);
else if (dirs[n] == 'W')
dfs(n + 1, x - 1, y);
else if (dirs[n] == 'E')
dfs(n + 1, x + 1, y);
else
{
dfs(n + 1, x, y - 1);
dfs(n + 1, x, y + 1);
dfs(n + 1, x - 1, y);
dfs(n + 1, x + 1, y);
}
}
int main()
{
int R, C, M;
cin >> R >> C >> M;
field.resize(R + 2, vector<bool>(C + 2, 0));
for (int i = 0; i < R; i++)
{
string str;
cin >> str;
for (int e = 0; e < str.size(); e++)
field[i + 1][e + 1] = str[e] == '.';
}
cin >> dirs;
int sum = 0;
for (int x = 0; x < C; x++)
for (int y = 0; y < R; y++)
dfs(0, x + 1, y + 1);
sum = 0;
for (int x = 0; x < C; x++)
{
for (int y = 0; y < R; y++)
{
if (lastpos[y + 1][x + 1])
sum++;
}
}
cout << sum;
return 0;
}
Compilation message
nautilus.cpp: In function 'void dfs(int, int, int)':
nautilus.cpp:16:11: 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 (n == dirs.size())
| ~~^~~~~~~~~~~~~~
nautilus.cpp: In function 'int main()':
nautilus.cpp:48:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
48 | for (int e = 0; e < str.size(); e++)
| ~~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
1336 KB |
Output is correct |
2 |
Correct |
1 ms |
1228 KB |
Output is correct |
3 |
Correct |
1 ms |
1228 KB |
Output is correct |
4 |
Correct |
1 ms |
716 KB |
Output is correct |
5 |
Correct |
1 ms |
688 KB |
Output is correct |
6 |
Correct |
1 ms |
716 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
1336 KB |
Output is correct |
2 |
Correct |
1 ms |
1228 KB |
Output is correct |
3 |
Correct |
1 ms |
1228 KB |
Output is correct |
4 |
Correct |
1 ms |
716 KB |
Output is correct |
5 |
Correct |
1 ms |
688 KB |
Output is correct |
6 |
Correct |
1 ms |
716 KB |
Output is correct |
7 |
Correct |
11 ms |
1376 KB |
Output is correct |
8 |
Correct |
5 ms |
1328 KB |
Output is correct |
9 |
Correct |
3 ms |
1228 KB |
Output is correct |
10 |
Correct |
2 ms |
972 KB |
Output is correct |
11 |
Correct |
1 ms |
688 KB |
Output is correct |
12 |
Correct |
14 ms |
1328 KB |
Output is correct |
13 |
Correct |
20 ms |
1304 KB |
Output is correct |
14 |
Correct |
14 ms |
1364 KB |
Output is correct |
15 |
Correct |
2 ms |
1356 KB |
Output is correct |
16 |
Correct |
1 ms |
716 KB |
Output is correct |
17 |
Correct |
16 ms |
1356 KB |
Output is correct |
18 |
Correct |
20 ms |
1356 KB |
Output is correct |
19 |
Correct |
8 ms |
1308 KB |
Output is correct |
20 |
Correct |
5 ms |
1356 KB |
Output is correct |
21 |
Correct |
1 ms |
716 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
1336 KB |
Output is correct |
2 |
Correct |
1 ms |
1228 KB |
Output is correct |
3 |
Correct |
1 ms |
1228 KB |
Output is correct |
4 |
Correct |
1 ms |
716 KB |
Output is correct |
5 |
Correct |
1 ms |
688 KB |
Output is correct |
6 |
Correct |
1 ms |
716 KB |
Output is correct |
7 |
Correct |
11 ms |
1376 KB |
Output is correct |
8 |
Correct |
5 ms |
1328 KB |
Output is correct |
9 |
Correct |
3 ms |
1228 KB |
Output is correct |
10 |
Correct |
2 ms |
972 KB |
Output is correct |
11 |
Correct |
1 ms |
688 KB |
Output is correct |
12 |
Correct |
14 ms |
1328 KB |
Output is correct |
13 |
Correct |
20 ms |
1304 KB |
Output is correct |
14 |
Correct |
14 ms |
1364 KB |
Output is correct |
15 |
Correct |
2 ms |
1356 KB |
Output is correct |
16 |
Correct |
1 ms |
716 KB |
Output is correct |
17 |
Correct |
16 ms |
1356 KB |
Output is correct |
18 |
Correct |
20 ms |
1356 KB |
Output is correct |
19 |
Correct |
8 ms |
1308 KB |
Output is correct |
20 |
Correct |
5 ms |
1356 KB |
Output is correct |
21 |
Correct |
1 ms |
716 KB |
Output is correct |
22 |
Runtime error |
9 ms |
1604 KB |
Execution killed with signal 11 |
23 |
Halted |
0 ms |
0 KB |
- |