Submission #139814

#TimeUsernameProblemLanguageResultExecution timeMemory
139814ae04071Nautilus (BOI19_nautilus)C++11
66 / 100
1071 ms632 KiB
#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)

nautilus.cpp: In function 'int main()':
nautilus.cpp:37:35: warning: array subscript has type 'char' [-Wchar-subscripts]
                 int yy=i+dy[arr[k]],xx=j+dx[arr[k]];
                                   ^
nautilus.cpp:37:51: warning: array subscript has type 'char' [-Wchar-subscripts]
                 int yy=i+dy[arr[k]],xx=j+dx[arr[k]];
                                                   ^
nautilus.cpp:20: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:21: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:22: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...