#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using db = double;
using str = string;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using pd = pair<db, db>;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<ll>;
using vd = vector<db>;
using vs = vector<str>;
using vpi = vector<pi>;
using vpl = vector<pl>;
using vpd = vector<pd>;
#define mp make_pair
#define f first
#define s second
#define sz(x) (int)(x).size()
#define bg(x) begin(x)
#define all(x) bg(x), end(x)
#define sor(x) sort(all(x))
#define ft front()
#define bk back()
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define EACH(a,x) for (auto& a: x)
const int MOD = 1e9 + 7;
const int MXR = 510;
const int MXM = 5010;
const ll INF = 2e18 + 10;
int R, C, M; string S; bitset<MXR> DP[MXM][MXR], grid[MXR];
int main() {
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> R >> C >> M; FOR(i, 1, R + 1) FOR(j, 1, C + 1) {
char A; cin >> A; if (A == '.') { DP[0][i][j] = 1; grid[i][j] = 1; }
}
cin >> S; FOR(i, 1, sz(S)) FOR(j, 1, R + 1) {
if (S[i] == 'N' || S[i] == '?') DP[i][j] |= DP[i - 1][j + 1];
if (S[i] == 'S' || S[i] == '?') DP[i][j] |= DP[i - 1][j - 1];
if (S[i] == 'W' || S[i] == '?') DP[i][j] |= DP[i - 1][j] << 1, DP[i][j][0] = 0;
if (S[i] == 'E' || S[i] == '?') DP[i][j] |= DP[i - 1][j] >> 1, DP[i][j][C + 1] = 0;
DP[i][j] &= grid[j];
}
int ans = 0; FOR(i, 1, R + 1) ans += DP[M - 1][i].count(); cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1228 KB |
Output is correct |
2 |
Incorrect |
2 ms |
1356 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1228 KB |
Output is correct |
2 |
Incorrect |
2 ms |
1356 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1228 KB |
Output is correct |
2 |
Incorrect |
2 ms |
1356 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |