Submission #447637

#TimeUsernameProblemLanguageResultExecution timeMemory
447637PiejanVDCPatkice (COCI20_patkice)C++17
0 / 50
327 ms524292 KiB
#include <bits/stdc++.h> using namespace std; int n,m; vector<string>v; map<pair<int,int>,int>mp; int dfs(int i, int j) { if(v[i][j] == 'x') return 0; if(v[i][j] == '.') return -1; if(mp.count({i,j})) return mp[{i,j}]; if(v[i][j] == 'v') { int ans = dfs(i+1,j); if(ans != -1) { return mp[{i,j}] = 1 + ans; } else return mp[{i,j}] =-1; } else if(v[i][j] == '^') { int ans = dfs(i-1,j); if(ans != -1) { return mp[{i,j}] = 1 + ans; } else return mp[{i,j}] =-1; } else if(v[i][j] == '>') { int ans = dfs(i,j+1); if(ans != -1) { return mp[{i,j}] = 1 + ans; } else return mp[{i,j}] =-1; } else { int ans = dfs(i,j-1); if(ans != -1) { return mp[{i,j}] = 1 + ans; } else return mp[{i,j}] =-1; } } signed main() { cin>>n>>m; v.resize(n); for(auto &z : v) cin>>z; pair<int,int>s; for(int i = 0 ; i < n ; i++) { for(int j = 0 ; j < m ; j++) { if(v[i][j] == 'o') s.first=i,s.second=j; } } char win; int64_t best = INT_MAX, ans; ans=dfs(s.first,s.second+1); if(ans != -1 && ans < best) { win = 'E',best=ans; } ans=dfs(s.first-1,s.second); if(ans != -1 && ans < best) { win = 'N',best=ans; } ans=dfs(s.first+1,s.second); if(ans!=-1&&ans < best) { win = 'S',best=ans; } ans=dfs(s.first,s.second-1); if(ans != -1 && ans < best) { win = 'W',best=ans; } if(best < INT_MAX) cout << ":)\n" << win; else cout << ":("; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...