#include<bits/stdc++.h>
using namespace std;
const long long inf = (long long) 1e18 + 10;
const int inf1 = (int) 1e9 + 10;
#define dbl long double
#define endl '\n'
#define sc second
#define fr first
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
const int maxn = 550;
int r,c,m;
bitset<maxn> dp[2][maxn], a[maxn];
vector<pair<int,int>> adj = {mp(0,-1),mp(0,1),mp(1,0),mp(-1,0)};
void solve() {
cin >> r >> c >> m;
for(int i = 0; i < r; i++) {
string s; cin >> s;
for(int j = 0; j < c; j++) {
if(s[j] == '.') a[i+1][j+1] = 1;
}
}
string s; cin >> s;
for(int i = 1; i <= r; i++) {
for(int j = 1; j <= c; j++) {
dp[0][i][j] = a[i][j];
}
}
for(int k = 1; k <= m; k++) {
for(int i = 1; i <= r; i++) {
if(s[k-1] == '?') {
dp[k&1][i] = a[i]&((dp[k&1^1][i]>>1)|(dp[k&1^1][i]<<1)|(dp[k&1^1][i-1])|(dp[k&1^1][i+1]));
}
else {
if(s[k-1] == 'S') dp[k&1][i] = a[i]&dp[k&1^1][i-1];
if(s[k-1] == 'N') dp[k&1][i] = a[i]&dp[k&1^1][i+1];
if(s[k-1] == 'W') dp[k&1][i] = a[i]&(dp[k&1^1][i]>>1);
if(s[k-1] == 'E') dp[k&1][i] = a[i]&(dp[k&1^1][i]<<1);
}
}
}
int ans = 0;
for(int i = 1; i <= r; i++) {
for(int j = 1; j <= c; j++) {
ans+= dp[m&1][i][j];
}
}
cout << ans << endl;
}
int32_t main() {
ios::sync_with_stdio(false); cin.tie(0);
// freopen("in.in", "r", stdin);
// freopen("out.out", "w", stdout);
int tt = 1;
// cin >> tt;
while(tt--) {
solve();
}
}
Compilation message
nautilus.cpp: In function 'void solve()':
nautilus.cpp:38:41: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
38 | dp[k&1][i] = a[i]&((dp[k&1^1][i]>>1)|(dp[k&1^1][i]<<1)|(dp[k&1^1][i-1])|(dp[k&1^1][i+1]));
| ~^~
nautilus.cpp:38:59: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
38 | dp[k&1][i] = a[i]&((dp[k&1^1][i]>>1)|(dp[k&1^1][i]<<1)|(dp[k&1^1][i-1])|(dp[k&1^1][i+1]));
| ~^~
nautilus.cpp:38:77: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
38 | dp[k&1][i] = a[i]&((dp[k&1^1][i]>>1)|(dp[k&1^1][i]<<1)|(dp[k&1^1][i-1])|(dp[k&1^1][i+1]));
| ~^~
nautilus.cpp:38:94: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
38 | dp[k&1][i] = a[i]&((dp[k&1^1][i]>>1)|(dp[k&1^1][i]<<1)|(dp[k&1^1][i-1])|(dp[k&1^1][i+1]));
| ~^~
nautilus.cpp:41:57: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
41 | if(s[k-1] == 'S') dp[k&1][i] = a[i]&dp[k&1^1][i-1];
| ~^~
nautilus.cpp:42:57: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
42 | if(s[k-1] == 'N') dp[k&1][i] = a[i]&dp[k&1^1][i+1];
| ~^~
nautilus.cpp:43:58: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
43 | if(s[k-1] == 'W') dp[k&1][i] = a[i]&(dp[k&1^1][i]>>1);
| ~^~
nautilus.cpp:44:58: warning: suggest parentheses around arithmetic in operand of '^' [-Wparentheses]
44 | if(s[k-1] == 'E') dp[k&1][i] = a[i]&(dp[k&1^1][i]<<1);
| ~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
412 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
412 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
312 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
412 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
312 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
2 ms |
340 KB |
Output is correct |
22 |
Correct |
91 ms |
700 KB |
Output is correct |
23 |
Correct |
99 ms |
704 KB |
Output is correct |
24 |
Correct |
85 ms |
596 KB |
Output is correct |
25 |
Correct |
82 ms |
704 KB |
Output is correct |
26 |
Correct |
81 ms |
672 KB |
Output is correct |
27 |
Correct |
134 ms |
596 KB |
Output is correct |
28 |
Correct |
136 ms |
700 KB |
Output is correct |
29 |
Correct |
121 ms |
600 KB |
Output is correct |
30 |
Correct |
125 ms |
696 KB |
Output is correct |
31 |
Correct |
123 ms |
676 KB |
Output is correct |
32 |
Correct |
158 ms |
700 KB |
Output is correct |
33 |
Correct |
158 ms |
700 KB |
Output is correct |
34 |
Correct |
155 ms |
600 KB |
Output is correct |
35 |
Correct |
162 ms |
616 KB |
Output is correct |
36 |
Correct |
154 ms |
596 KB |
Output is correct |