#include <bitset>
#include <iostream>
#include <vector>
using namespace std;
using map_t = vector<bitset<500>>;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int r, c, m;
cin >> r >> c >> m;
map_t map(500);
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
char ch;
cin >> ch;
if (ch == '.')
map[i][j] = true;
}
}
string s;
cin >> s;
map_t cur = map;
map_t next(500);
for (char const& ch : s) {
switch (ch) {
case 'N':
for (int i = 0; i < r - 1; i++) {
cur[i] = cur[i + 1];
cur[i] &= map[i];
}
cur[r - 1].reset();
break;
case 'S':
for (int i = r - 1; i > 0; i--) {
cur[i] = cur[i - 1];
cur[i] &= map[i];
}
cur[0].reset();
break;
case 'E':
case 'W':
for (int i = 0; i < r; i++) {
// indices are swapped, so the shift direction is swapped
if (ch == 'E')
cur[i] <<= 1;
else
cur[i] >>= 1;
cur[i] &= map[i];
}
break;
case '?':
for (int i = 0; i < r; i++) {
next[i].reset();
if (i > 0)
next[i] |= cur[i - 1];
if (i + 1 < r)
next[i] |= cur[i + 1];
next[i] |= cur[i] << 1;
next[i] |= cur[i] >> 1;
next[i] &= map[i];
}
swap(next, cur);
break;
}
#ifdef _DEBUG
cout << ch << ":\n";
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
if (!map[i][j])
cout << "#";
else if (cur[i][j])
cout << "X";
else
cout << ".";
}
cout << "\n";
}
#endif
}
int ans = 0;
for (int i = 0; i < r; i++)
ans += cur[i].count();
cout << ans << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
464 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
464 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
464 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
464 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
716 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
388 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
604 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
464 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
464 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
716 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
388 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
604 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
49 ms |
600 KB |
Output is correct |
23 |
Correct |
51 ms |
604 KB |
Output is correct |
24 |
Correct |
51 ms |
788 KB |
Output is correct |
25 |
Correct |
49 ms |
788 KB |
Output is correct |
26 |
Correct |
49 ms |
788 KB |
Output is correct |
27 |
Correct |
84 ms |
604 KB |
Output is correct |
28 |
Correct |
93 ms |
604 KB |
Output is correct |
29 |
Correct |
86 ms |
600 KB |
Output is correct |
30 |
Correct |
86 ms |
604 KB |
Output is correct |
31 |
Correct |
89 ms |
600 KB |
Output is correct |
32 |
Correct |
113 ms |
604 KB |
Output is correct |
33 |
Correct |
111 ms |
600 KB |
Output is correct |
34 |
Correct |
112 ms |
788 KB |
Output is correct |
35 |
Correct |
116 ms |
848 KB |
Output is correct |
36 |
Correct |
110 ms |
788 KB |
Output is correct |