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;
typedef pair<ll, ll> pll;
#define fastio ios::sync_with_stdio(false), cin.tie(0)
#pragma GCC optimize("Ofast")
#define pb push_back
#define eb emplace_back
#define f first
#define s second
#define lowbit(x) x&-x
const int maxn = 2e5 + 5;
signed main(void){
fastio;
int r, c, m;
cin>>r>>c>>m;
vector<bitset<501>> st(r);
for(int i = 0; i < r; i++){
string s;
cin>>s;
for(int j = 0; j < c; j++){
if(s[j] == '.') st[i][j] = 1;
}
}
string op;
cin>>op;
vector<bitset<501>> cur(st);
for(int i = 0; i < m; i++){
vector<bitset<501>> nw(r);
if(op[i] == 'E' || op[i] == '?'){
for(int j = 0; j < r; j++){
nw[j] |= (cur[j] << 1);
nw[j] &= st[j];
}
}
if(op[i] == 'W' || op[i] == '?'){
for(int j = 0; j < r; j++){
nw[j] |= (cur[j] >> 1);
nw[j] &= st[j];
}
}
if(op[i] == 'N' || op[i] == '?'){
for(int j = r - 2; j >= 0; j--){
nw[j] |= cur[j + 1];
nw[j] &= st[j];
}
}
if(op[i] == 'S' || op[i] == '?'){
bitset<501> acc;
for(int j = 1; j < r; j++){
nw[j] |= cur[j - 1];
nw[j] &= st[j];
}
}
swap(cur, nw);
}
int ans = 0;
for(int i = 0; i < r; i++) ans += cur[i].count();
cout<<ans<<"\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |