//Bismillahir-Rahmanir-Rahim
#include <bits/stdc++.h>
using namespace std;
#define flash ios_base::sync_with_stdio(0),cin.tie(0)
#define pb push_back
#define ll long long
#define ld long double
#define dbg(x) cerr << #x << " = " << x << "\n";
#define ff first
#define ss second
/*
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma comment (linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
*/
const long long INF = 1e9 + 7;
const long long MOD = 1e9 + 7;
const int maxn = 1e6 + 10;
const int lg = 20;
int n, m, k;
bitset <555> a[555], b[555], N[555], W[555], S[555], E[555], nw[555];
string s;
void press_F_() {
cin >> n >> m >> k;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
char x;
cin >> x;
if (x == '.') {
a[i][j] = 1;
} else {
b[i][j] = 1;
}
}
}
cin >> s;
for (auto to: s) {
if (to == 'N') {
for (int i = n; i >= 1; i--) {
a[i] = a[i - 1];
}
for (int i = 1; i <= n; i++) {
a[i] &= b[i];
}
continue;
}
if (to == 'S') {
for (int i = 1; i <= n; i++) {
a[i] = a[i + 1];
}
for (int i = 1; i <= n; i++) {
a[i] &= b[i];
}
continue;
}
if (to == 'W') {
for (int i = 1; i <= n; i++) {
a[i] >>= 1;
a[i] &= b[i];
}
continue;
}
if (to == 'E') {
for (int i = 1; i <= n; i++) {
a[i] <<= 1;
a[i] &= b[i];
}
continue;
}
for (int i = 1; i <= n; i++) {
W[i] = a[i];
S[i] = a[i];
N[i] = a[i];
E[i] = a[i];
}
for (int i = n; i >= 1; i--) {
N[i] = N[i - 1];
}
for (int i = 1; i <= n; i++) {
N[i] &= b[i];
}
for (int i = 1; i <= n; i++) {
S[i] = S[i + 1];
}
for (int i = 1; i <= n; i++) {
S[i] &= b[i];
}
for (int i = 1; i <= n; i++) {
W[i] >>= 1;
W[i] &= b[i];
}
for (int i = 1; i <= n; i++) {
E[i] <<= 1;
E[i] &= b[i];
}
for (int i = 1; i <= n; i++) {
nw[i] = 0;
nw[i] |= W[i];
nw[i] |= N[i];
nw[i] |= S[i];
nw[i] |= E[i];
a[i] = nw[i];
}
}
int ans = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (a[i][j] == 1) {
ans++;
}
}
}
cout << ans;
}
int main() {
flash;
int T = 1;
// cin >> T;
for (int i = 1; i <= T; i++) {
press_F_();
}
//Respa gold 2023-2024 InshAllah
return 0;
}
/*
Maybe not today and tomorrow, but InshAllah one day I will reach expert
*/
// g++ -std=c++17 main.cpp
// ./a.out
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |