#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) begin(x), end(x)
#define sz(x) (int)x.size()
#define pb push_back
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n, m, k;
cin >> n >> m >> k;
vector<bitset<500>> x(n), b(n), b1(n);
for(int i=0; i<n; i++){
for(int j=0; j<m; j++){
char c; cin >> c;
if(c == '.') x[i][j] = 1;
}
}
b = x;
bitset<500> y;
for(int i=0; i<m; i++) y[i] = 1;
string s; cin >> s;
for(auto c: s){
if(c == 'N'){
for(int i=0; i<n-1; i++){
swap(b[i], b[i+1]);
}
b[n-1].reset();
}
else if(c == 'S'){
for(int i=n-1; i>0; i--){
swap(b[i], b[i-1]);
}
b[0].reset();
}
else if(c == 'W'){
for(int i=0; i<n; i++){
b[i] = (b[i]>>1);
}
}
else if(c == 'E'){
for(int i=0; i<n; i++){
b[i] = (b[i]<<1);
b[i] &= y;
}
}
else{
for(int i=0; i<n; i++){
if(i-1 >= 0){
b1[i] |= b[i-1];
}
if(i+1 < n){
b1[i] |= b[i+1];
}
}
for(int i=0; i<n; i++){
b[i] = (b[i]<<1)|(b[i]>>1);
b[i] &= y;
}
for(int i=0; i<n; i++){
b[i] |= b1[i];
b1[i].reset();
}
}
for(int i=0; i<n; i++){
b[i] = (b[i]&x[i]);
}
}
int ans = 0;
for(int i=0; i<n; i++){
ans += b[i].count();
}
cout << ans;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |