Submission #445809

#TimeUsernameProblemLanguageResultExecution timeMemory
445809JasiekstrzPatkice (COCI20_patkice)C++17
50 / 50
1 ms716 KiB
#include<bits/stdc++.h> #define fi first #define se second using namespace std; const int INF=1e9+7; const int N=100; bool ok[N+10][N+10]; vector<pair<int,int>> e[N+10][N+10]; int dfs(int x,int y) { if(ok[x][y]) return 1; if(e[x][y].empty()) return INF; return dfs(e[x][y][0].fi,e[x][y][0].se)+1; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n,m; cin>>n>>m; pair<int,int> s; for(int i=1;i<=n;i++) { for(int j=1;j<=m;j++) { char c; cin>>c; if(c=='x') ok[i][j]=true; if(c=='o') s={i,j}; if(c=='<') e[i][j].emplace_back(i,j-1); if(c=='>') e[i][j].emplace_back(i,j+1); if(c=='^') e[i][j].emplace_back(i-1,j); if(c=='v') e[i][j].emplace_back(i+1,j); } } int ans=INF; char g=0; vector<tuple<int,int,char>> moves={{0,1,'E'},{-1,0,'N'},{1,0,'S'},{0,-1,'W'}}; for(auto [i,j,c]:moves) { int tmp=dfs(s.fi+i,s.se+j); if(tmp<ans) { ans=tmp; g=c; } } if(ans==INF) cout<<":(\n"; else cout<<":)\n"<<g<<"\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...