//gm --- akezhon
#include <bits/stdc++.h>
// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define pb push_back
#define pf push_front
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define pii pair<int,int>
#define tm (tl+tr)/2
#define TL v+v, tl, tm
#define TR v+v+1, tm+1, tr
#define DA l <= tl && tr <= r
#define NE r < tl || tr < l
#define double long double
// #define int long long
using namespace std;
const int N=1e5+7;
const int mod=998244353;
// const int inf=2e18;
bitset<505>b[505], temp[505], temp2[505], temp3[505], temp4[505], good[505];
void AlemAmenov(){
int n, m, k;
string s;
cin >> n >> m >> k;
string a[n+1];
for(int i=0; i < n; i++){
cin >> a[i];
for(int j=0; j < m; j++){
if(a[i][j]=='.')good[i][j]=1, b[i][j]=1;
}
}
cin >> s;
for(char c : s){
if(c=='N'){
for(int i=0; i < n-1; i++){
b[i] = b[i+1] & good[i];
}
b[n-1].reset();
}
else if(c=='S'){
for(int i=n-1; i >= 1; i--){
b[i] = b[i-1] & good[i];
}
b[0].reset();
}
else if(c=='W'){
for(int i=0; i < n; i++){
b[i] = (b[i] >> 1);
b[i][m-1] = 0;
b[i] &= good[i];
}
}
else if(c=='E'){
for(int i=0; i < n; i++){
b[i] = (b[i] << 1);
b[i][0] = 0;
b[i] &= good[i];
}
}
else{
for(int i=0; i < n-1; i++){
temp[i] = b[i+1];
}
temp[n-1].reset();
for(int i=1; i < n; i++){
temp4[i] = b[i-1];
}
temp4[0].reset();
for(int i=0; i < n; i++){
temp2[i] = (b[i] >> 1);
temp2[i][m-1] = 0;
temp3[i] = (b[i] << 1);
temp3[i][0] = 0;
}
for(int i=0; i < n; i++){
b[i] = (temp[i] | temp2[i] | temp3[i] | temp4[i]) & good[i];
}
}
}
int ans=0;
for(int i=0; i < n; i++){
ans += b[i].count();
}
cout << ans;
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int RealName=1;
// cin >> RealName;
// freopen("connect.in", "r", stdin);
// freopen("connect.out", "w", stdout);
while(RealName--)
AlemAmenov();
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... |