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;
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fs first
#define sc second
#define tlll tuple<ll,ll,ll>
const int mxn = 505;
bitset<mxn> dp[2][mxn];
bitset<mxn> mask[mxn];
int N,M,L;
string s;
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>N>>M>>L;
for(int i = 0;i<N;i++){
string ss;
cin>>ss;
for(int j = 0;j<M;j++){
mask[i][j] = (ss[j] == '#'?0:1);
}
dp[0][i] = mask[i];
}
cin>>s;
bool roll = 0;
for(auto it = s.begin();it != s.end();it++){
roll ^= 1;
for(int i = 0;i<N;i++)dp[roll][i].reset();
if(*it == 'W'||*it == '?'){
for(int i = 0;i<N;i++){
dp[roll][i] |= (dp[roll^1][i]>>1);
}
}
if(*it == 'E'||*it == '?'){
for(int i = 0;i<N;i++){
dp[roll][i] |= (dp[roll^1][i]<<1);
}
}
if(*it == 'N'||*it == '?'){
for(int i = 0;i+1<N;i++){
dp[roll][i] |= dp[roll^1][i+1];
}
}
if(*it == 'S'||*it == '?'){
for(int i = 1;i<N;i++){
dp[roll][i] |= dp[roll^1][i-1];
}
}
for(int i = 0;i<N;i++)dp[roll][i] &= mask[i];
/*
for(int i = 0;i<N;i++){
for(int j = 0;j<M;j++)cout<<(dp[roll][i][j]?1:0);cout<<endl;
}cout<<endl;
*/
}
int ans = 0;
for(int i = 0;i<N;i++){
for(int j = 0;j<M;j++)ans += (dp[roll][i][j]?1:0);
}
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... |