Submission #315251

#TimeUsernameProblemLanguageResultExecution timeMemory
315251dCodingNautilus (BOI19_nautilus)C++17
29 / 100
1086 ms504 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define F first #define S second const int MAXN=505; char grid[MAXN][MAXN]; char str[MAXN]; int n,m,k; bool ok[MAXN][MAXN]; void dfs(int x,int y,int idx) { if(x<0||y<0||x>=n||y>=m||grid[x][y]=='#') return; if(idx==k) { ok[x][y]=true; return; } if(str[idx]=='N') dfs(x-1,y,idx+1); else if(str[idx]=='S') dfs(x+1,y,idx+1); else if(str[idx]=='E') dfs(x,y+1,idx+1); else if(str[idx]=='W') dfs(x,y-1,idx+1); else { dfs(x-1,y,idx+1); dfs(x+1,y,idx+1); dfs(x,y+1,idx+1); dfs(x,y-1,idx+1); } } int main() { scanf("%d%d%d",&n,&m,&k); for(int i=0;i<n;i++) scanf("%s",grid[i]); scanf("%s",str); for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { dfs(i,j,0); } } int ans=0; for(int i=0;i<n;i++) { for(int j=0;j<m;j++) { ans+=ok[i][j]; } } printf("%d",ans); } /* 5 9 7 ...##.... ..#.##..# ..#....## .##...#.. ....#.... WS?EE?? */

Compilation message (stderr)

nautilus.cpp: In function 'int main()':
nautilus.cpp:32:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   32 |  scanf("%d%d%d",&n,&m,&k);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~
nautilus.cpp:33:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   33 |  for(int i=0;i<n;i++) scanf("%s",grid[i]);
      |                       ~~~~~^~~~~~~~~~~~~~
nautilus.cpp:34:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   34 |  scanf("%s",str);
      |  ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...