#include <bits/stdc++.h>
using namespace std;
#define REP(i, l, r) for(int i = (l); i < (r); ++i)
#define FOR(i, l, r) for(int i = (l); i <= (r); ++i)
#define FORD(i, r, l) for(int i = (r); i >= (l); --i)
#define ff first
#define ss second
#define eb emplace_back
#define pb push_back
#define all(x) x.begin(), x.end()
#define sz(v) (int)v.size()
#define compact(v) v.erase(unique(all(v)), v.end())
#define dbg(v) "[" #v " = " << (v) << "]"
#define el "\n"
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
template<class T> bool minimize(T& a, const T& b){ if(a > b) return a = b, true; return false; }
template<class T> bool maximize(T& a, const T& b){ if(a < b) return a = b, true; return false; }
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
long long randRange(long long l, long long r){ return uniform_int_distribution<long long>(l,r)(rng); }
const int N = 500;
int n, m, k;
string op;
bitset<500> a[2][500], b[500];
void solve() {
cin >> n >> m >> k;
REP(i, 0, n) {
REP(j, 0, m) {
char c; cin >> c;
a[0][i][j] = (c == '#' ? 0 : 1);
}
b[i] = a[0][i];
}
int cur = 1, prv = 0;
cin >> op;
REP(_, 0, k) {
char t = op[_];
if (t == 'N') {
FORD(i, n - 2, 0) a[cur][i] = a[prv][i + 1] & b[i];
}
else if (t == 'E') {
FOR(i, 0, n - 1) a[cur][i] = (a[prv][i] >> 1) & b[i];
}
else if (t == 'S') {
FOR(i, 1, n - 1) a[cur][i] = a[prv][i - 1] & b[i];
}
else if (t == 'W') {
FOR(i, 0, n - 1) a[cur][i] = (a[prv][i] << 1) & b[i];
}
else {
FOR(i, 0, n - 1) {
a[cur][i] = ((a[prv][i] >> 1) | (a[prv][i] << 1));
}
FOR(i, 1, n - 1) a[cur][i] |= a[prv][i - 1];
FORD(i, n - 2, 0) a[cur][i] |= a[prv][i + 1];
FOR(i, 0, n - 1) a[cur][i] &= b[i];
}
swap(cur, prv);
}
ll ans = 0;
FOR(i, 0, n - 1) {
ans += a[prv][i].count();
}
cout << ans << el;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
#define task "task"
if(fopen(task".inp", "r")) {
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
solve();
return 0;
}
/*
*/
Compilation message (stderr)
nautilus.cpp: In function 'int main()':
nautilus.cpp:93:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
93 | freopen(task".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
nautilus.cpp:94:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
94 | freopen(task".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |