Submission #163185

#TimeUsernameProblemLanguageResultExecution timeMemory
163185TadijaSebezSandwich (JOI16_sandwich)C++11
35 / 100
8061 ms6748 KiB
#include <bits/stdc++.h> using namespace std; const int N=405; const int inf=N*N*2; char mat[N][N]; int mv[4][2]={{0,1},{-1,0},{0,-1},{1,0}}; int was[N][N]; int DFS(int x, int y, int dir) { if(mat[x][y]!='N' && mat[x][y]!='Z') return 0; if(was[x][y]==2) return 0; if(was[x][y]==1) return inf; int ans=2,xr; if(mat[x][y]=='N') xr=1; else xr=3; was[x][y]=1; ans+=DFS(x+mv[dir][0],y+mv[dir][1],dir); ans+=DFS(x+mv[dir^xr][0],y+mv[dir^xr][1],dir^xr); was[x][y]=2; return ans; } void cl(){ for(int i=0;i<N;i++) for(int j=0;j<N;j++) was[i][j]=0;} int main() { int n,m; scanf("%i %i",&n,&m); for(int i=1;i<=n;i++) scanf("%s",mat[i]+1); for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) { int ans=DFS(i,j,0);cl(); ans=min(ans,DFS(i,j,2));cl(); if(ans>=inf) printf("-1 "); else printf("%i ",ans); if(j==m) printf("\n"); } return 0; }

Compilation message (stderr)

sandwich.cpp: In function 'int main()':
sandwich.cpp:26:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%i %i",&n,&m);
  ~~~~~^~~~~~~~~~~~~~~
sandwich.cpp:27:29: 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",mat[i]+1);
                        ~~~~~^~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...