This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
using namespace std;
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <map>
#include <set>
#include <stack>
#include <queue>
typedef long long LL;
typedef pair<int,int> pii;
#define pb push_back
#define mkp make_pair
#define F first
#define S second
#define iter(x) x.begin(),x.end()
#define REP(n) for (int __=n;__--;)
#define REP0(i,n) for (int i=0;i<n;++i)
#define REP1(i,n) for (int i=1;i<=n;++i)
#include <bitset>
const int maxn = 505, mod = 0;
const LL inf = 0;
vector <bitset <maxn>> dp, can;
void solve(){
int n, m, k;
cin >> n >> m >> k;
can.resize(n);
REP0(i,n) REP0(j,m){
char c;
cin >> c;
can[i][j] = (c == '.');
}
//REP0(i,n) {REP0(j,m) cout << can[i][j]; cout << '\n';} cout << '\n';
dp = can;
REP(k){
char c;
vector <bitset<maxn>> tr(n);
cin >> c;
if (c == 'E' or c == '?'){
REP0(i,n) tr[i] = tr[i] | (dp[i] << 1);
}
if (c == 'W' or c == '?'){
REP0(i,n) tr[i] = tr[i] | (dp[i] >> 1);
}
if (c == 'N' or c == '?'){
REP0(i,n-1) tr[i] = tr[i] | dp[i+1];
}
if (c == 'S' or c == '?'){
REP1(i,n-1) tr[i] = tr[i] | dp[i-1];
}
REP0(i, n){
tr[i] = tr[i] & can[i];
}
dp.swap(tr);
//cout << c << '\n'; REP0(i,n) {REP0(j,m) cout << dp[i][j]; cout << '\n';} cout << '\n';
}
int cnt = 0;
REP0(i,n) cnt += dp[i].count();
cout << cnt;
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0);
solve();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |