//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;
b[i][j] = 1;
}
}
}
cin >> s;
for (auto to: s) {
if (to == 'N') {
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 == 'S') {
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 == '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 = 1; i <= n; i++) {
N[i] = N[i + 1];
}
for (int i = 1; i <= n; i++) {
N[i] &= b[i];
}
for (int i = n; i >= 1; 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 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
472 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
476 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
472 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
476 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
2 ms |
344 KB |
Output is correct |
17 |
Correct |
2 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
476 KB |
Output is correct |
21 |
Correct |
1 ms |
552 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
472 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
476 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
2 ms |
344 KB |
Output is correct |
17 |
Correct |
2 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
344 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
476 KB |
Output is correct |
21 |
Correct |
1 ms |
552 KB |
Output is correct |
22 |
Correct |
78 ms |
860 KB |
Output is correct |
23 |
Correct |
78 ms |
860 KB |
Output is correct |
24 |
Correct |
73 ms |
976 KB |
Output is correct |
25 |
Correct |
75 ms |
1116 KB |
Output is correct |
26 |
Correct |
72 ms |
856 KB |
Output is correct |
27 |
Correct |
149 ms |
860 KB |
Output is correct |
28 |
Correct |
140 ms |
856 KB |
Output is correct |
29 |
Correct |
147 ms |
856 KB |
Output is correct |
30 |
Correct |
140 ms |
860 KB |
Output is correct |
31 |
Correct |
141 ms |
948 KB |
Output is correct |
32 |
Correct |
188 ms |
976 KB |
Output is correct |
33 |
Correct |
193 ms |
972 KB |
Output is correct |
34 |
Correct |
192 ms |
856 KB |
Output is correct |
35 |
Correct |
194 ms |
860 KB |
Output is correct |
36 |
Correct |
194 ms |
956 KB |
Output is correct |