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;
typedef long long ll;
#define ll int
typedef pair<int,int> pi;
typedef vector <int> vi;
typedef vector <pi> vpi;
typedef pair<pi, ll> pii;
typedef set <ll> si;
typedef long double ld;
#define f first
#define s second
#define mp make_pair
#define FOR(i,s,e) for(int i=s;i<=int(e);++i)
#define DEC(i,s,e) for(int i=s;i>=int(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define maxn 505
#define maxt 5005
#define INF (ll)1e18
#define MOD 1000000007
typedef pair <vi, int> pvi;
typedef pair <int,pi> ipi;
typedef vector <pii> vpii;
int R,C,M;
bool A[maxn][maxn];
char S[maxt], ch;
bool dp[maxn][maxn][maxt];
int32_t main(){
cin >> R >> C >> M;
FOR(i,1,R) FOR(j,1,C){
cin >> ch; A[i][j] = (ch == '.');
}
FOR(i,1,M) cin >> S[i];
FOR(i,1,R) FOR(j,1,C){
dp[i][j][0] = A[i][j];
}
FOR(t,1,M){
FOR(i,1,R) FOR(j,1,C){
if (S[t] == 'E'){
dp[i][j][t] = (dp[i][j-1][t-1] & A[i][j]);
}else if (S[t] == 'W'){
dp[i][j][t] = (dp[i][j+1][t-1] & A[i][j]);
}else if (S[t] == 'S') dp[i][j][t] = (dp[i-1][j][t-1] & A[i][j]);
else if (S[t] == 'N') dp[i][j][t] = (dp[i+1][j][t-1] & A[i][j]);
else{
dp[i][j][t] = ((dp[i-1][j][t-1] | dp[i+1][j][t-1] | dp[i][j-1][t-1] | dp[i][j+1][t-1]) & A[i][j]);
}
}
}
int ans = 0;
FOR(i,1,R) FOR(j,1,C) ans += dp[i][j][M];
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... |