This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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) + 1) FOR(j, 1, R + 1) {
if (S[i - 1] == 'N' || S[i - 1] == '?') DP[i][j] |= DP[i - 1][j + 1];
if (S[i - 1] == 'S' || S[i - 1] == '?') DP[i][j] |= DP[i - 1][j - 1];
if (S[i - 1] == 'W' || S[i - 1] == '?') DP[i][j] |= DP[i - 1][j] >> 1, DP[i][j][C + 1] = 0;
if (S[i - 1] == 'E' || S[i - 1] == '?') DP[i][j] |= DP[i - 1][j] << 1, DP[i][j][0] = 0;
DP[i][j] &= grid[j];
}
int ans = 0; FOR(i, 1, R + 1) ans += DP[M][i].count(); cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |