# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
139813 | ae04071 | Nautilus (BOI19_nautilus) | C++11 | 1025 ms | 2812 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,dp[2][510][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);
memset(dp,-1,sizeof(dp));
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]=0;
}
for(int i=0;i<l;i++) arr[i] = get(arr[i]);
int cur=1,pr=0;
for(int k=0;k<l;k++) {
if(arr[k]) {
for(int i=1;i<=n;i++)for(int j=1;j<=m;j++) if(dp[pr][i][j]==k) {
int yy=i+dy[arr[k]],xx=j+dx[arr[k]];
if(str[yy][xx])
dp[cur][yy][xx]=k+1;
}
} else {
for(int i=1;i<=n;i++)for(int j=1;j<=m;j++) if(dp[pr][i][j]==k) for(int t=1;t<=4;t++) {
int yy=i+dy[t],xx=j+dx[t];
if(str[yy][xx])
dp[cur][yy][xx]=k+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]==l) 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... |