#include <bits/stdc++.h>
using namespace std;
int r, c, m;
string a[100], s;
int main(){
cin >> r >> c >> m;
for(int i = 0; i < r; i++) cin >> a[i];
cin >> s;
bitset<1000> dp[r], temp[r], aa[r];
for(int i = 0; i < r; i++) for(int j = 0; j < c; j++) dp[i][j] = aa[i][j] = a[i][c - j - 1];
for(auto dir : s){
for(int i = 0; i < r; i++){
if(dir == 'N') {
if(i + 1 < r) dp[i] = dp[i + 1] & aa[i];
else dp[i].reset();
}
if(dir == 'E') dp[i] = (dp[i] >> 1) & aa[i];
if(dir == 'W') dp[i] = (dp[i] << 1) & aa[i];
if(dir == '?'){
temp[i] = (dp[i] >> 1) | (dp[i] << 1);
if(i) temp[i] |= dp[i -1];
if(i + 1 < r) temp[i] |= dp[i + 1];
temp[i] &= aa[i];
}
}
for(int i = r - 1; i > -1; i--){
if(dir == 'S'){
if(i) dp[i] = dp[i - 1] & aa[i];
else dp[i].reset();
}
}
for(int i = 0; i < r; i++) if(dir == '?') dp[i] = temp[i];
}
int ans = 0;
for(int i = 0; i < r; i++) ans += dp[i].count();
cout << ans << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |