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>
#define fr(i, n, m) for(int i = (n); i < (m); i ++)
#define pb push_back
#define st first
#define nd second
#define pq priority_queue
#define all(x) begin(x), end(x)
#include <time.h>
#include <cmath>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
const int i_inf = 1e4;
const ll inf = 1e17;
const ll mod = 1000000007;
const ld eps = 1e-13;
const ld pi = 3.14159265359;
mt19937 _rand(time(NULL));
clock_t timer = clock();
const int mxn = 200005;
int n, m, k;
bitset<500> dp[500];
bitset<500> cop[500];
bitset<500> mapa[500];
bitset<500> rem;
bitset<500> emp;
void solve(){
cin >> n >> m >> k;
fr(i, 0, m) rem[i] = 1;
fr(i, 0, n){
fr(j, 0, m){
char c;
cin >> c;
if(c == '.') dp[i][j] = 1;
if(c == '.') mapa[i][j] = 1;
}
}
string s;
cin >> s;
fr(i, 0, k){
if(s[i] == 'W'){
fr(j, 0, n){
dp[j] >>= 1;
}
}
else if(s[i] == 'E'){
fr(j, 0, n){
dp[j] <<= 1;
}
}
else if(s[i] == 'N'){
fr(j, 0, n-1){
dp[j] = dp[j+1];
}
dp[n-1].reset();
}
else if(s[i] == 'S'){
for(int j = n-1; j > 0; j --){
dp[j] = dp[j-1];
}
dp[0].reset();
}
else{
fr(j, 0, n){
if(j == 0) cop[j] = dp[j+1];
else if(j == n-1) cop[j] = dp[j-1];
else cop[j] = dp[j-1]|dp[j+1];
}
fr(j, 0, n){
dp[j] = cop[j]|(dp[j]>>1)|(dp[j]<<1);
}
}
fr(j, 0, n) dp[j] = dp[j]&mapa[j];
}
int ans = 0;
fr(i, 0, n) ans += dp[i].count();
cout<<ans<<endl;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |