#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mxN = 5e2 + 5, mod = 1e9 + 7, LOG = 20;
int r, c, m;
bool a[mxN][mxN];
bitset <mxN * mxN> A, B;
int main() {
ios :: sync_with_stdio(false), cin.tie(nullptr);
cin >> r >> c >> m;
for (int i = 1; i <= r; ++i) {
for (int j = 1; j <= c; ++j) {
char b;
cin >> b;
a[i][j] = (b == '.');
A[i * mxN + j] = B[i * mxN + j] = a[i][j];
}
}
string s;
cin >> s;
for (int i = 0; i < m; ++i) {
if (s[i] == 'S') A <<= mxN;
else if (s[i] == 'N') A >>= mxN;
else if (s[i] == 'W') A >>= 1;
else if (s[i] == 'E') A <<= 1;
else if (s[i] == '?') A = (A << mxN) | (A >> mxN) | (A >> 1) | (A << 1);
A &= B; // only water parts should be remained
}
cout << A.count();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
588 KB |
Output is correct |
2 |
Correct |
1 ms |
588 KB |
Output is correct |
3 |
Correct |
1 ms |
588 KB |
Output is correct |
4 |
Correct |
1 ms |
588 KB |
Output is correct |
5 |
Correct |
2 ms |
588 KB |
Output is correct |
6 |
Correct |
1 ms |
588 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
588 KB |
Output is correct |
2 |
Correct |
1 ms |
588 KB |
Output is correct |
3 |
Correct |
1 ms |
588 KB |
Output is correct |
4 |
Correct |
1 ms |
588 KB |
Output is correct |
5 |
Correct |
2 ms |
588 KB |
Output is correct |
6 |
Correct |
1 ms |
588 KB |
Output is correct |
7 |
Correct |
2 ms |
588 KB |
Output is correct |
8 |
Correct |
2 ms |
588 KB |
Output is correct |
9 |
Correct |
2 ms |
588 KB |
Output is correct |
10 |
Correct |
2 ms |
588 KB |
Output is correct |
11 |
Correct |
2 ms |
588 KB |
Output is correct |
12 |
Correct |
3 ms |
648 KB |
Output is correct |
13 |
Correct |
3 ms |
608 KB |
Output is correct |
14 |
Correct |
3 ms |
588 KB |
Output is correct |
15 |
Correct |
3 ms |
588 KB |
Output is correct |
16 |
Correct |
3 ms |
588 KB |
Output is correct |
17 |
Correct |
4 ms |
588 KB |
Output is correct |
18 |
Correct |
4 ms |
588 KB |
Output is correct |
19 |
Correct |
4 ms |
588 KB |
Output is correct |
20 |
Correct |
4 ms |
652 KB |
Output is correct |
21 |
Correct |
4 ms |
588 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
588 KB |
Output is correct |
2 |
Correct |
1 ms |
588 KB |
Output is correct |
3 |
Correct |
1 ms |
588 KB |
Output is correct |
4 |
Correct |
1 ms |
588 KB |
Output is correct |
5 |
Correct |
2 ms |
588 KB |
Output is correct |
6 |
Correct |
1 ms |
588 KB |
Output is correct |
7 |
Correct |
2 ms |
588 KB |
Output is correct |
8 |
Correct |
2 ms |
588 KB |
Output is correct |
9 |
Correct |
2 ms |
588 KB |
Output is correct |
10 |
Correct |
2 ms |
588 KB |
Output is correct |
11 |
Correct |
2 ms |
588 KB |
Output is correct |
12 |
Correct |
3 ms |
648 KB |
Output is correct |
13 |
Correct |
3 ms |
608 KB |
Output is correct |
14 |
Correct |
3 ms |
588 KB |
Output is correct |
15 |
Correct |
3 ms |
588 KB |
Output is correct |
16 |
Correct |
3 ms |
588 KB |
Output is correct |
17 |
Correct |
4 ms |
588 KB |
Output is correct |
18 |
Correct |
4 ms |
588 KB |
Output is correct |
19 |
Correct |
4 ms |
588 KB |
Output is correct |
20 |
Correct |
4 ms |
652 KB |
Output is correct |
21 |
Correct |
4 ms |
588 KB |
Output is correct |
22 |
Correct |
99 ms |
752 KB |
Output is correct |
23 |
Correct |
80 ms |
1112 KB |
Output is correct |
24 |
Correct |
74 ms |
1132 KB |
Output is correct |
25 |
Correct |
71 ms |
1100 KB |
Output is correct |
26 |
Correct |
70 ms |
1100 KB |
Output is correct |
27 |
Correct |
127 ms |
1120 KB |
Output is correct |
28 |
Correct |
123 ms |
1100 KB |
Output is correct |
29 |
Correct |
131 ms |
1120 KB |
Output is correct |
30 |
Correct |
131 ms |
1100 KB |
Output is correct |
31 |
Correct |
128 ms |
1100 KB |
Output is correct |
32 |
Correct |
171 ms |
1116 KB |
Output is correct |
33 |
Correct |
158 ms |
1220 KB |
Output is correct |
34 |
Correct |
166 ms |
1120 KB |
Output is correct |
35 |
Correct |
184 ms |
1120 KB |
Output is correct |
36 |
Correct |
157 ms |
1116 KB |
Output is correct |