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 ff first
#define int long long
#define ss second
#define pb push_back
const int N=5e3+5;
const int NM=501;
char arr[NM][NM];
bitset<NM> dp[NM];
bitset<NM>rck[NM];
bitset<NM>fll[NM];
signed main(){
int n,m,k;
cin>>n>>m>>k;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin>>arr[i][j];
}
}
string s;
cin>>s;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
if(arr[i][j]=='#'){
rck[i][j]=0;
continue;
}
rck[i][j]=1;
dp[i][j]=1;
}
}
for(int l=0;l<k;l++){
bitset<NM>tmp[NM];
for(int i=1;i<=n;i++){
tmp[i]&=fll[i];
tmp[i]|=dp[i];
dp[i]&=fll[i];
}
if(s[l]=='E'){
for(int i=1;i<=n;i++){
dp[i]|=(tmp[i]<<1);
dp[i]&=rck[i];
}
}
else if(s[l]=='W'){
for(int i=1;i<=n;i++){
dp[i]|=(tmp[i]>>1);
dp[i]&=rck[i];
}
}
else if(s[l]=='N'){
for(int i=1;i<=m;i++){
dp[i-1]|=tmp[i];
dp[i-1]&=rck[i-1];
}
}
else if(s[l]=='S'){
for(int i=1;i<=m;i++){
dp[i+1]|=tmp[i];
dp[i+1]&=rck[i+1];
}
}
else{
for(int i=1;i<=n;i++){
dp[i]|=(tmp[i]<<1);
dp[i]&=rck[i];
}
for(int i=1;i<=n;i++){
dp[i]|=(tmp[i]>>1);
dp[i]&=rck[i];
}
for(int i=1;i<=m;i++){
dp[i-1]|=tmp[i];
dp[i-1]&=rck[i-1];
}
for(int i=1;i<=m;i++){
dp[i+1]|=tmp[i];
dp[i+1]&=rck[i+1];
}
}
}
int cnt=0;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cnt+= dp[i][j];
}
}
cout<<cnt;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |