Submission #915355

#TimeUsernameProblemLanguageResultExecution timeMemory
915355vjudge1Patkice (COCI20_patkice)C++17
50 / 50
1 ms444 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define int ll #define ii pair<int,int> #define F first #define S second #define endl '\n' const int N = 105; char a[N][N]; signed main(){ int r, s; cin >> r >> s; ii start, target; for(int i=0; i<r; ++i){ for(int j=0; j<s; ++j){ cin >> a[i][j]; if(a[i][j] == 'o'){ start = {i, j}; } if(a[i][j] == 'x'){ target = {i, j}; } } } auto dfs = [&](ii cur, auto&& dfs) -> int { if(cur == target) return 0; if(a[cur.F][cur.S] == '.') return 4e18; if(a[cur.F][cur.S] == '<'){ int tmp = dfs({cur.F, cur.S-1}, dfs); if(tmp != 4e18){ return 1 + tmp; } return 4e18; } if(a[cur.F][cur.S] == '>'){ int tmp = dfs({cur.F, cur.S+1}, dfs); if(tmp != 4e18){ return 1 + tmp; } return 4e18; } if(a[cur.F][cur.S] == '^'){ int tmp = dfs({cur.F-1, cur.S}, dfs); if(tmp != 4e18){ return 1 + tmp; } return 4e18; } if(a[cur.F][cur.S] == 'v'){ int tmp = dfs({cur.F+1, cur.S}, dfs); if(tmp != 4e18){ return 1 + tmp; } return 4e18; } return 4e18; }; string aux = "ENSW"; vector<int> ans(4); ans[0] = dfs(make_pair(start.F, start.S+1), dfs); ans[1] = dfs(make_pair(start.F-1, start.S), dfs); ans[2] = dfs(make_pair(start.F+1, start.S), dfs); ans[3] = dfs(make_pair(start.F, start.S-1), dfs); int mn = min({ans[0], ans[1], ans[2], ans[3]}); if(mn == 4e18){ cout << ":("; return 0; } for(int i=0; i<4; ++i){ if(ans[i] == mn){ cout << ":)\n"; cout << aux[i]; return 0; } } assert(0); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...