#include <bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 500;
signed main() {
#ifndef ONLINE_JUDGE
// for getting input from input.txt
//freopen("input.txt", "r", stdin);
// for writing output to output.txt
//freopen("output.txt", "w", stdout);
#endif
/*#ifdef ONLINE_JUDGE
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#endif*/ //fast IO
int n,m,k;
cin >> n >> m >> k;
bitset<maxn> B;
bitset<maxn> all0;
vector<bitset<maxn>> grid(n,B);
vector<bitset<maxn>> allowed(n,B);
for (int i=0; i<n; i++) {
string s;
cin >> s;
bitset<maxn> B1;
for (int j=0; j<m; j++) {
if (s[j]=='#') {
B1[j] = 0;
}
else {
B1[j] = 1;
}
}
grid[i] = allowed[i] = B1;
}
for (int let=0; let<k; let++) {
char c;
cin >> c;
//cout << let << " " << c << endl;
if (c=='N') {
for (int i=1; i<n; i++) {
allowed[i-1] = allowed[i];
}
allowed[n-1] = all0;
}
else if (c=='S') {
for (int i=n-2; i>=0; i--) {
//cout << "downing " << i << endl;
allowed[i+1] = allowed[i];
}
allowed[0] = all0;
}
else if (c=='W') {
for (int i=0; i<n; i++) {
allowed[i] >>= 1;
}
}
else if (c=='E') {
for (int i=0; i<n; i++) {
allowed[i] <<= 1;
}
}
else if (c=='?') {
//cout << "d" << let << endl;
vector<bitset<maxn>> allowed2(n,all0);
//cout << "e" << let << endl;
for (int i=0; i<n; i++) {
//cout << "doing " << i << endl;
allowed2[i] |= allowed[i]>>1;
allowed2[i] |= allowed[i]<<1;
}
for (int i=n-2; i>=0; i--) {
//cout << i << endl;
allowed2[i+1] |= allowed[i];
}
for (int i=1; i<n; i++) {
//cout << i << endl;
allowed2[i-1] |= allowed[i];
}
allowed=allowed2;
}
else {
assert(false);
}
for (int i=0; i<n; i++) {
allowed[i] &= grid[i];
}
}
int answer = 0;
for (int i=0; i<n; i++) {
answer+=allowed[i].count();
}
cout << answer << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 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 |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
436 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 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 |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
436 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
52 ms |
612 KB |
Output is correct |
23 |
Correct |
52 ms |
756 KB |
Output is correct |
24 |
Correct |
50 ms |
752 KB |
Output is correct |
25 |
Correct |
49 ms |
604 KB |
Output is correct |
26 |
Correct |
49 ms |
604 KB |
Output is correct |
27 |
Correct |
106 ms |
752 KB |
Output is correct |
28 |
Correct |
102 ms |
768 KB |
Output is correct |
29 |
Correct |
95 ms |
600 KB |
Output is correct |
30 |
Correct |
105 ms |
604 KB |
Output is correct |
31 |
Correct |
100 ms |
604 KB |
Output is correct |
32 |
Correct |
126 ms |
600 KB |
Output is correct |
33 |
Correct |
121 ms |
604 KB |
Output is correct |
34 |
Correct |
117 ms |
600 KB |
Output is correct |
35 |
Correct |
133 ms |
604 KB |
Output is correct |
36 |
Correct |
137 ms |
600 KB |
Output is correct |