#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
typedef pair<ll,ll> pll;
void cppio(){ ios_base::sync_with_stdio(0); cin.tie(0); }
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
#define x first
#define y second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define sz(x) (int)(x).size()
#define XY(p) p.x, p.y
int n, m, k;
char c[5010];
typedef bitset<500> BIT[500];
BIT sc[2], ok;
int main()
{
cppio(); cin >> n >> m >> k;
{ static char buf[510]; rep(i, n) {
cin >> buf;
rep(j, m) if (buf[j] == '.') ok[i][j] = 1;
} }
cin >> c;
int cur = 0;
rep(i, n) sc[cur][i] = ok[i];
rep(ki, k) {
auto dp = sc[cur];
switch(c[ki]) {
case 'E':
rep(i, n) dp[i] = ((dp[i]<<1)&ok[i]);
break;
case 'W':
rep(i, n) dp[i] = ((dp[i]>>1)&ok[i]);
break;
case 'N':
rep(i, n-1) dp[i] = ((dp[i+1])&ok[i]);
dp[n-1].reset();
break;
case 'S':
for(int i=n-1; 1<=i; --i)
dp[i] = ((dp[i-1])&ok[i]);
dp[0].reset();
break;
case '?':
auto tmp = sc[cur^1];
rep(i, n) {
tmp[i] = ((dp[i]<<1) | (dp[i]>>1));
if (i)
tmp[i] |= dp[i-1];
if (i+1 < n)
tmp[i] |= dp[i+1];
}
rep(i, n) tmp[i] &= ok[i];
cur ^= 1;
break;
}
}
int ans = 0;
rep(i, n) ans += sc[cur][i].count();
cout << ans << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
416 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
416 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
74 ms |
640 KB |
Output is correct |
23 |
Correct |
78 ms |
760 KB |
Output is correct |
24 |
Correct |
73 ms |
640 KB |
Output is correct |
25 |
Correct |
73 ms |
736 KB |
Output is correct |
26 |
Correct |
73 ms |
760 KB |
Output is correct |
27 |
Correct |
112 ms |
768 KB |
Output is correct |
28 |
Correct |
108 ms |
640 KB |
Output is correct |
29 |
Correct |
113 ms |
640 KB |
Output is correct |
30 |
Correct |
110 ms |
732 KB |
Output is correct |
31 |
Correct |
108 ms |
640 KB |
Output is correct |
32 |
Correct |
136 ms |
760 KB |
Output is correct |
33 |
Correct |
139 ms |
760 KB |
Output is correct |
34 |
Correct |
137 ms |
672 KB |
Output is correct |
35 |
Correct |
146 ms |
760 KB |
Output is correct |
36 |
Correct |
155 ms |
640 KB |
Output is correct |