#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3,unroll-loops")
using namespace std;
#define int long long
#define pii pair<int,int>
#define ff first
#define ss second
#define sp << " " <<
#define all(cont) cont.begin(),cont.end()
#define vi vector<int>
const int inf = 1e17,N = 2e6+1,MOD = (1LL<<61)-1,B = 23;
void solve() {
int n,m,q;
cin >> n >> m >> q;
bitset<360000> board;
auto idx = [&](int r,int c) {
return (r+1)*(m+2)+(c+1);
};
for (int i = 0;i<n;i++) {
string s;
cin >> s;
for (int j = 0;j<m;j++) {
board[idx(i,j)] = (s[j] == '.');
}
}
bitset<360000> b2;
bitset<360000> init = board;
string ops;
cin >> ops;
for (auto c : ops) {
if (c == 'W') {
board >>= 1;
}
else if (c == 'E') {
board <<= 1;
}
else if (c == 'S') {
board <<= (m+2);
}
else if (c == 'N') {
board >>= (m+2);
}
else {
b2.reset();
b2|=(board << 1);
b2|=(board >> 1);
b2|=(board >> (m+2));
b2|=(board << (m+2));
board = b2;
}
board&=init;
}
int ans = 0;
for (int i = 0;i<n;i++) {
for (int j = 0;j<m;j++) {
ans+=board[idx(i,j)];
}
}
cout << ans << '\n';
}
int32_t main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#ifdef Dodi
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
int t = 1;
//cin >> t;
while (t --> 0) solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |