#include <iostream>
#include <bitset>
#include <algorithm>
using namespace std;
const int mx = 500;
int main()
{
bitset<(mx+2) * (mx+2)> grid, DP0, DP1;
grid.reset();
int R, C, M;
cin >> R >> C >> M;
for(int i = 1; i <= R; i++)
{
for(int j = 1; j <= C; j++)
{
char c;
cin >> c;
if(c == '.')
grid.set((mx+2) * i + j);
}
}
// cerr << "\n";
// for(int i = 0; i < (mx+2)*(mx+2); i++)
// {
// cerr << grid[i];
// if(i % (mx+2) == mx+1) cerr << '\n';
// }
string S;
cin >> S;
// reverse(S.b
DP0 = grid;
for(char c : S)
{
// cerr << "\n\n\n c = " << c << '\n';
if(c == 'N') DP1 = (DP0 >> (mx+2));
else if(c == 'S') DP1 = (DP0 << (mx+2));
else if(c == 'W') DP1 = (DP0 >> 1);
else if(c == 'E') DP1 = (DP0 << 1);
else
{
DP1 = (DP0 << (mx+2)) | (DP0 >> (mx+2)) | (DP0 << 1) | (DP0 >> 1);
}
DP1 &= grid;
// for(int i = 0; i < (mx+2)*(mx+2); i++)
// {
// if(grid[i] == 0) cerr << "#";
// else cerr << DP0[i];
// if(i % (mx+2) == mx+1) cerr << '\n';
// }
// cerr << "\n---->\n";
// for(int i = 0; i < (mx+2)*(mx+2); i++)
// {
// if(grid[i] == 0) cerr << "#";
// else cerr << DP1[i];
// if(i % (mx+2) == mx+1) cerr << '\n';
// }
swap(DP0, DP1);
}
cout << DP0.count() << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
588 KB |
Output is correct |
2 |
Correct |
2 ms |
588 KB |
Output is correct |
3 |
Correct |
2 ms |
588 KB |
Output is correct |
4 |
Correct |
2 ms |
588 KB |
Output is correct |
5 |
Correct |
2 ms |
604 KB |
Output is correct |
6 |
Correct |
2 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
588 KB |
Output is correct |
2 |
Correct |
2 ms |
588 KB |
Output is correct |
3 |
Correct |
2 ms |
588 KB |
Output is correct |
4 |
Correct |
2 ms |
588 KB |
Output is correct |
5 |
Correct |
2 ms |
604 KB |
Output is correct |
6 |
Correct |
2 ms |
600 KB |
Output is correct |
7 |
Correct |
2 ms |
588 KB |
Output is correct |
8 |
Correct |
3 ms |
604 KB |
Output is correct |
9 |
Correct |
3 ms |
588 KB |
Output is correct |
10 |
Correct |
3 ms |
588 KB |
Output is correct |
11 |
Correct |
3 ms |
604 KB |
Output is correct |
12 |
Correct |
3 ms |
588 KB |
Output is correct |
13 |
Correct |
6 ms |
588 KB |
Output is correct |
14 |
Correct |
4 ms |
588 KB |
Output is correct |
15 |
Correct |
4 ms |
588 KB |
Output is correct |
16 |
Correct |
4 ms |
608 KB |
Output is correct |
17 |
Correct |
5 ms |
604 KB |
Output is correct |
18 |
Correct |
5 ms |
588 KB |
Output is correct |
19 |
Correct |
5 ms |
604 KB |
Output is correct |
20 |
Correct |
4 ms |
608 KB |
Output is correct |
21 |
Correct |
5 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
588 KB |
Output is correct |
2 |
Correct |
2 ms |
588 KB |
Output is correct |
3 |
Correct |
2 ms |
588 KB |
Output is correct |
4 |
Correct |
2 ms |
588 KB |
Output is correct |
5 |
Correct |
2 ms |
604 KB |
Output is correct |
6 |
Correct |
2 ms |
600 KB |
Output is correct |
7 |
Correct |
2 ms |
588 KB |
Output is correct |
8 |
Correct |
3 ms |
604 KB |
Output is correct |
9 |
Correct |
3 ms |
588 KB |
Output is correct |
10 |
Correct |
3 ms |
588 KB |
Output is correct |
11 |
Correct |
3 ms |
604 KB |
Output is correct |
12 |
Correct |
3 ms |
588 KB |
Output is correct |
13 |
Correct |
6 ms |
588 KB |
Output is correct |
14 |
Correct |
4 ms |
588 KB |
Output is correct |
15 |
Correct |
4 ms |
588 KB |
Output is correct |
16 |
Correct |
4 ms |
608 KB |
Output is correct |
17 |
Correct |
5 ms |
604 KB |
Output is correct |
18 |
Correct |
5 ms |
588 KB |
Output is correct |
19 |
Correct |
5 ms |
604 KB |
Output is correct |
20 |
Correct |
4 ms |
608 KB |
Output is correct |
21 |
Correct |
5 ms |
604 KB |
Output is correct |
22 |
Correct |
97 ms |
840 KB |
Output is correct |
23 |
Correct |
100 ms |
812 KB |
Output is correct |
24 |
Correct |
96 ms |
848 KB |
Output is correct |
25 |
Correct |
95 ms |
964 KB |
Output is correct |
26 |
Correct |
90 ms |
832 KB |
Output is correct |
27 |
Correct |
128 ms |
856 KB |
Output is correct |
28 |
Correct |
173 ms |
844 KB |
Output is correct |
29 |
Correct |
144 ms |
836 KB |
Output is correct |
30 |
Correct |
134 ms |
844 KB |
Output is correct |
31 |
Correct |
129 ms |
840 KB |
Output is correct |
32 |
Correct |
173 ms |
844 KB |
Output is correct |
33 |
Correct |
170 ms |
844 KB |
Output is correct |
34 |
Correct |
167 ms |
832 KB |
Output is correct |
35 |
Correct |
169 ms |
840 KB |
Output is correct |
36 |
Correct |
171 ms |
968 KB |
Output is correct |