# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
139814 | ae04071 | Nautilus (BOI19_nautilus) | C++11 | 1071 ms | 632 KiB |
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;
int n,m,l;
bitset<511> dp[2][510];
int dy[]={0,-1,0,0,1},dx[]={0,0,-1,1,0};
char str[511][511],arr[5010];
inline int get(char ch) {
switch(ch) {
case 'N': return 1;
case 'W': return 2;
case 'E': return 3;
case 'S': return 4;
default: return 0;
}
}
int main() {
scanf("%d%d%d",&n,&m,&l);
for(int i=1;i<=n;i++) scanf("%s",str[i]+1);
scanf("%s",arr);
for(int i=1;i<=n;i++)for(int j=1;j<=m;j++) {
str[i][j] = str[i][j]=='.';
if(str[i][j]) dp[0][i][j]=1;
}
for(int i=0;i<l;i++) arr[i] = get(arr[i]);
int cur=1,pr=0;
for(int k=0;k<l;k++) {
for(int i=1;i<=n;i++) dp[cur][i].reset();
if(arr[k]) {
for(int i=1;i<=n;i++)for(int j=1;j<=m;j++) if(dp[pr][i][j]) {
int yy=i+dy[arr[k]],xx=j+dx[arr[k]];
if(str[yy][xx])
dp[cur][yy][xx]=1;
}
} else {
for(int i=1;i<=n;i++)for(int j=1;j<=m;j++) if(dp[pr][i][j]) for(int t=1;t<=4;t++) {
int yy=i+dy[t],xx=j+dx[t];
if(str[yy][xx])
dp[cur][yy][xx]=1;
}
}
swap(cur,pr);
}
int ans=0;
for(int i=1;i<=n;i++)for(int j=1;j<=m;j++) if(dp[pr][i][j]) ans++;
printf("%d\n",ans);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |