Submission #139813

#TimeUsernameProblemLanguageResultExecution timeMemory
139813ae04071Nautilus (BOI19_nautilus)C++11
66 / 100
1025 ms2812 KiB
#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)

nautilus.cpp: In function 'int main()':
nautilus.cpp:35:35: warning: array subscript has type 'char' [-Wchar-subscripts]
                 int yy=i+dy[arr[k]],xx=j+dx[arr[k]];
                                   ^
nautilus.cpp:35:51: warning: array subscript has type 'char' [-Wchar-subscripts]
                 int yy=i+dy[arr[k]],xx=j+dx[arr[k]];
                                                   ^
nautilus.cpp:19:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d%d",&n,&m,&l);
     ~~~~~^~~~~~~~~~~~~~~~~~~
nautilus.cpp:20:32: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i=1;i<=n;i++) scanf("%s",str[i]+1);
                           ~~~~~^~~~~~~~~~~~~~~
nautilus.cpp:21:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%s",arr);
     ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...