Submission #448125

#TimeUsernameProblemLanguageResultExecution timeMemory
448125jk410Patkice (COCI20_patkice)C++17
50 / 50
1 ms332 KiB
#include <bits/stdc++.h> using namespace std; const int INF=1e9; int N,M,sx,sy; int dx[4]={0,-1,1,0},dy[4]={1,0,0,-1},Time[4]; bool Visited[100][100]; string A[100]; int dfs(int x,int y){ if (x<0||x>=N||y<0||y>=M||Visited[x][y]||A[x][y]=='.') return INF; if (A[x][y]=='x') return 0; Visited[x][y]=true; for (int i=0; i<4; i++){ if (A[x][y]==">^v<"[i]){ int tmp=dfs(x+dx[i],y+dy[i]); if (tmp==INF) return INF; return tmp+1; } } } int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>N>>M; for (int i=0; i<N; i++){ cin>>A[i]; for (int j=0; j<M; j++){ if (A[i][j]=='o'){ sx=i; sy=j; } } } for (int i=0; i<4; i++){ memset(Visited,false,sizeof(Visited)); A[sx][sy]=">^v<"[i]; Time[i]=dfs(sx,sy); } int Min=INF,idx; for (int i=0; i<4; i++){ if (Time[i]<Min){ Min=Time[i]; idx=i; } } if (Min==INF) cout<<":("; else cout<<":)\n"<<"ENSW"[idx]; return 0; }

Compilation message (stderr)

patkice.cpp: In function 'int dfs(int, int)':
patkice.cpp:22:1: warning: control reaches end of non-void function [-Wreturn-type]
   22 | }
      | ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...