#include <bits/stdc++.h>
#define ll long long
#define pll pair<ll,ll>
#define pb push_back
#define eb emplace_back
#define vl vector<ll>
#define fi first
#define se second
#define in insert
#define mpr make_pair
#define lg(x) __lg(x)
#define bpc(x) __builtin_popcount(x)
#define all(v) v.begin(), v.end()
#define endl "\n"
using namespace std;
const int mod = 998244353;
const long long inf = 1000000000000000000;
const int sz = 505; /// mind the sz
bitset<sz> dp[2][sz], water[sz], x, y;
char a[sz][sz];
ll n, m;
void print(bitset<sz> A){
for(ll i = 1; i<=m; i++){
cout << A[i] << ' ';
}
cout << endl;
}
void solve(){
ll i, j, k, c = 1;
cin>>n>>m>>k;
for(i=1;i<=n;i++){
for(j=1;j<=m;j++){
cin>>a[i][j];
if(a[i][j] == '.'){
dp[0][i].set(j, 1);
water[i].set(j, 1);
}
}
}
string s;
cin >> s;
s = "*" + s;
for(i=1;i<=k;i++){
for(j=1;j<=n;j++){
dp[c][j] = x;
if((s[i] == 'N' || s[i] == '?') && j < n){
dp[c][j] |= dp[c ^ 1][j + 1];
}
if((s[i] == 'S' || s[i] == '?') && j > 1){
dp[c][j] |= dp[c ^ 1][j - 1];
}
if(s[i] == 'W' || s[i] == '?'){
dp[c][j] |= (dp[c ^ 1][j] >> 1);
}
if(s[i] == 'E' || s[i] == '?'){
dp[c][j] |= (dp[c ^ 1][j] << 1);
}
// print(dp[c][j]);
// print(water[j]);
dp[c][j] &= water[j];
// print(dp[c][j]);
}
c ^= 1;
// break;
}
ll cnt = 0;
for(i=1;i<=n;i++){
//cout << i << " -> ";
for(j=1;j<=m;j++){
if(dp[k % 2][i][j]){
//cout << j << ' ';
cnt++;
}
}
//cout << endl;
}
cout << cnt << endl;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll tst=1;
//cin>>tst; //MIND THIS
while(tst--){
solve();
}
}
/*
1
6
4 1 6 3 10 7
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
768 KB |
Output is correct |
5 |
Correct |
1 ms |
348 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 |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
768 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 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 |
344 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 |
348 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 |
468 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 |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
768 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 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 |
344 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 |
348 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 |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
64 ms |
1044 KB |
Output is correct |
23 |
Correct |
81 ms |
1048 KB |
Output is correct |
24 |
Correct |
64 ms |
1048 KB |
Output is correct |
25 |
Correct |
64 ms |
860 KB |
Output is correct |
26 |
Correct |
64 ms |
856 KB |
Output is correct |
27 |
Correct |
93 ms |
1052 KB |
Output is correct |
28 |
Correct |
92 ms |
856 KB |
Output is correct |
29 |
Correct |
101 ms |
856 KB |
Output is correct |
30 |
Correct |
93 ms |
1048 KB |
Output is correct |
31 |
Correct |
91 ms |
1028 KB |
Output is correct |
32 |
Correct |
125 ms |
1048 KB |
Output is correct |
33 |
Correct |
113 ms |
856 KB |
Output is correct |
34 |
Correct |
123 ms |
1044 KB |
Output is correct |
35 |
Correct |
118 ms |
1104 KB |
Output is correct |
36 |
Correct |
112 ms |
860 KB |
Output is correct |