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<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<unordered_map>
#include <queue>
#include<cstring>
#include<limits.h>
#include <cassert>
#include<cmath>
#include<set>
#include<algorithm>
#include <iomanip>
#include<numeric> //gcd(a,b)
#include<bitset>
using namespace std;
#define ll long long
#define f first
#define endl "\n"
#define s second
#define pii pair<int,int>
#define ppii pair<int,pii>
#define vi vector<int>
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define F(n) for(int i=0;i<n;i++)
#define lb lower_bound
#define ub upper_bound
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
#pragma GCC optimize ("03,unroll-loops")
using namespace std;
#define int long long
const int mod=998244353,mxn=500+5,lg=30,inf=1e18,minf=-1e18,Mxn=501*501;
int n,m,sz;
bitset<505*505>yes,l,r,clear;
int32_t main(){
fastio
cin>>n>>m>>sz;
for(int i=0;i<=n*(m+1);i++)l[i]=r[i]=true;
bitset<505*505>dp;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
char a;cin>>a;
if(a=='.')dp[i*m+j]=yes[i*m+j]=true;
else yes[i*m+j]=false;
clear[i*m+j]=true;
}
}
for(int i=0;i<505*505;i+=m){
l[i]=false;
r[i+m-1]=false;
}
string k;cin>>k;
for(int i=0;i<sz;i++){
bitset<505*505>cdp,gol,gor;
gol=dp&l;
gor=dp&r;
if(k[i]=='N'||k[i]=='?')cdp|=(dp>>m);
if(k[i]=='S'||k[i]=='?')cdp|=(dp<<m);
if(k[i]=='W'||k[i]=='?')cdp|=(gol>>1);
if(k[i]=='E'||k[i]=='?')cdp|=(gor<<1);
cdp&=yes;
swap(dp,cdp);
}
int sum=0;
for(int i=0;i<n;i++)for(int j=0;j<m;j++)sum+=dp[i*m+j];
cout<<sum;
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... |