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 LCBorz ios_base::sync_with_stdio(false); cin.tie(0);
//#define int long long
#define all(x) x.begin(), x.end()
#define endl '\n'
const int N=505;
const int INF=1e9;
int32_t main() {
LCBorz;
bitset<N> grid[N],dp[N],dp1[N];
int n,m,t;cin>>n>>m>>t;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
char c;cin>>c;
grid[i][j]=dp[i][j]=(c=='.');
}
}
string s;cin>>s;
for(char c:s){
for(int i=0;i<n;i++){
dp1[i].reset();
}
if(c=='W'||c=='?'){
for(int i=0;i<n;i++)dp1[i]|=dp[i]>>1;
}
if(c=='E'||c=='?'){
for(int i=0;i<n;i++)dp1[i]|=dp[i]<<1;
}
if(c=='N'||c=='?'){
for(int i=0;i<n;i++)dp1[i]|=dp[i+1];
}
if(c=='S'||c=='?'){
for(int i=1;i<n;i++)dp1[i]|=dp[i-1];
}
for(int i=0;i<n;i++){
dp[i]=dp1[i]&grid[i];
}
}
int ans=0;
for(int i=0;i<n;i++){
ans+=dp[i].count();
}
cout<<ans<<endl;
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... |