#pragma GCC optimize("-Ofast")
#include <iostream>
#include <vector>
#include <algorithm>
#include <bitset>
#define int int64_t
using namespace std;
signed main()
{
int r, c, m;
cin >> r >> c >> m;
vector<bitset<500>> tab;
vector<bitset<500>> st(r, bitset<500>());
vector<bitset<500>> old(r, bitset<500>());
for (int i = 0; i < r; i++)
{
for (int j = 0; j < c; j++)
{
char ch;
cin >> ch;
st[i][j] = (ch == '.');
}
}
tab = st;
string seq;
cin >> seq;
for (int t = 0; t < m; t++)
{
swap(old, tab);
for (int i = 0; i < r; i++)
{
tab[i] = 0;
if ((seq[t] == 'S' || seq[t] == '?') && i > 0) tab[i] = tab[i] | old[i - 1];
if (seq[t] == 'W' || seq[t] == '?') tab[i] = tab[i] | (old[i] >> 1);
if ((seq[t] == 'N' || seq[t] == '?') && i + 1 < r) tab[i] = tab[i] | old[i + 1];
if (seq[t] == 'E' || seq[t] == '?') tab[i] = tab[i] | (old[i] << 1);
tab[i] &= st[i];
}
/*
for (auto v : tab)
{
for (int i = 0; i < 10; i++)
{
cout << v[i];
}
cout << "\n";
}
cout << "\n";
*/
}
int res = 0;
for (auto v : tab) res = res + v.count();
cout << res << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
376 KB |
Output is correct |
2 |
Correct |
6 ms |
376 KB |
Output is correct |
3 |
Correct |
6 ms |
376 KB |
Output is correct |
4 |
Correct |
6 ms |
376 KB |
Output is correct |
5 |
Correct |
6 ms |
376 KB |
Output is correct |
6 |
Correct |
6 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
376 KB |
Output is correct |
2 |
Correct |
6 ms |
376 KB |
Output is correct |
3 |
Correct |
6 ms |
376 KB |
Output is correct |
4 |
Correct |
6 ms |
376 KB |
Output is correct |
5 |
Correct |
6 ms |
376 KB |
Output is correct |
6 |
Correct |
6 ms |
376 KB |
Output is correct |
7 |
Correct |
6 ms |
376 KB |
Output is correct |
8 |
Correct |
6 ms |
376 KB |
Output is correct |
9 |
Correct |
6 ms |
376 KB |
Output is correct |
10 |
Correct |
6 ms |
376 KB |
Output is correct |
11 |
Correct |
6 ms |
376 KB |
Output is correct |
12 |
Correct |
6 ms |
376 KB |
Output is correct |
13 |
Correct |
7 ms |
376 KB |
Output is correct |
14 |
Correct |
6 ms |
380 KB |
Output is correct |
15 |
Correct |
6 ms |
248 KB |
Output is correct |
16 |
Correct |
6 ms |
376 KB |
Output is correct |
17 |
Correct |
6 ms |
376 KB |
Output is correct |
18 |
Correct |
6 ms |
376 KB |
Output is correct |
19 |
Correct |
6 ms |
376 KB |
Output is correct |
20 |
Correct |
6 ms |
376 KB |
Output is correct |
21 |
Correct |
6 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
376 KB |
Output is correct |
2 |
Correct |
6 ms |
376 KB |
Output is correct |
3 |
Correct |
6 ms |
376 KB |
Output is correct |
4 |
Correct |
6 ms |
376 KB |
Output is correct |
5 |
Correct |
6 ms |
376 KB |
Output is correct |
6 |
Correct |
6 ms |
376 KB |
Output is correct |
7 |
Correct |
6 ms |
376 KB |
Output is correct |
8 |
Correct |
6 ms |
376 KB |
Output is correct |
9 |
Correct |
6 ms |
376 KB |
Output is correct |
10 |
Correct |
6 ms |
376 KB |
Output is correct |
11 |
Correct |
6 ms |
376 KB |
Output is correct |
12 |
Correct |
6 ms |
376 KB |
Output is correct |
13 |
Correct |
7 ms |
376 KB |
Output is correct |
14 |
Correct |
6 ms |
380 KB |
Output is correct |
15 |
Correct |
6 ms |
248 KB |
Output is correct |
16 |
Correct |
6 ms |
376 KB |
Output is correct |
17 |
Correct |
6 ms |
376 KB |
Output is correct |
18 |
Correct |
6 ms |
376 KB |
Output is correct |
19 |
Correct |
6 ms |
376 KB |
Output is correct |
20 |
Correct |
6 ms |
376 KB |
Output is correct |
21 |
Correct |
6 ms |
376 KB |
Output is correct |
22 |
Correct |
74 ms |
480 KB |
Output is correct |
23 |
Correct |
73 ms |
636 KB |
Output is correct |
24 |
Correct |
81 ms |
760 KB |
Output is correct |
25 |
Correct |
75 ms |
632 KB |
Output is correct |
26 |
Correct |
74 ms |
632 KB |
Output is correct |
27 |
Correct |
86 ms |
632 KB |
Output is correct |
28 |
Correct |
92 ms |
760 KB |
Output is correct |
29 |
Correct |
88 ms |
632 KB |
Output is correct |
30 |
Correct |
93 ms |
632 KB |
Output is correct |
31 |
Correct |
89 ms |
632 KB |
Output is correct |
32 |
Correct |
107 ms |
632 KB |
Output is correct |
33 |
Correct |
106 ms |
632 KB |
Output is correct |
34 |
Correct |
93 ms |
632 KB |
Output is correct |
35 |
Correct |
96 ms |
760 KB |
Output is correct |
36 |
Correct |
94 ms |
632 KB |
Output is correct |