#include <bits/stdc++.h>
using namespace std;
void solve(){
int N, M, K; cin >> N >> M >> K;
string mat[N];
for(int i = 0; i < N; i++){
cin >> mat[i];
}
string path; cin >> path;
bitset<500> start[N], pre[N], cur[N];
for(int i = 0; i < N; i++){
for(int j = 0; j < M; j++) if(mat[i][j] == '.'){
start[i][j] = true;
cur[i][j] = true;
}
}
for(char c: path){
for(int i = 0; i < N; i++){
pre[i] = cur[i];
cur[i].reset();
}
if(c == 'N' || c == '?'){
for(int i = 1; i < N; i++){
cur[i - 1] |= pre[i];
}
}
if(c == 'S' || c == '?'){
for(int i = 0; i + 1 < N; i++){
cur[i + 1] |= pre[i];
}
}
if(c == 'W' || c == '?'){
for(int i = 0; i < N; i++){
cur[i] |= pre[i] >> 1;
}
}
if(c == 'E' || c == '?'){
for(int i = 0; i < N; i++){
cur[i] |= pre[i] << 1;
}
}
for(int i = 0; i < N; i++){
cur[i] &= start[i];
}
}
int ans = 0;
for(int i = 0; i < N; i++){
ans += cur[i].count();
}
cout << ans << '\n';
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
// freopen("SHIP.inp", "r", stdin);
// freopen("SHIP.out", "w", stdout);
int t = 1;
// cin >> t;
while(t--){
solve();
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |