Submission #515712

#TimeUsernameProblemLanguageResultExecution timeMemory
515712Hacv16Patkice (COCI20_patkice)C++17
50 / 50
1 ms344 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; const int MAX = 115; const int INF = 0x3f3f3f3f; const int MOD = 1e9 + 7; const int VAR[4] = {-1, 1, 0, 0}; #define pb push_back #define sz(x) (int) x.size() #define fr first #define sc second #define mp make_pair #define all(x) x.begin(), x.end() int n, m, dx, dy, ix, iy; map<char, pii> dir; char s[MAX][MAX]; void setIO(){ ios_base::sync_with_stdio(false); cin.tie(NULL); } int dfs(int x, int y){ if(s[x][y] == 'x') return 0; if(s[x][y] == '.' || s[x][y] == 'o') return INF; int nx = x + dir[s[x][y]].fr, ny = y + dir[s[x][y]].sc; return min(dfs(nx, ny) + 1, INF); } int main(){ setIO(); memset(s, '.', sizeof(s)); dir['^'] = {-1, 0}; dir['v'] = {1, 0}; dir['<'] = {0, -1}; dir['>'] = {0, 1}; cin >> n >> m; for(int i = 1; i <= n; i++){ for(int j = 1; j <= m; j++){ cin >> s[i][j]; if(s[i][j] == 'o') dx = i, dy = j; } } pair<int, char> ans = {INF, 'Z'}; ans = min(ans, {dfs(dx + 1, dy), 'S'}); ans = min(ans, {dfs(dx - 1, dy), 'N'}); ans = min(ans, {dfs(dx, dy + 1), 'E'}); ans = min(ans, {dfs(dx, dy - 1), 'W'}); if(ans.fr == INF) cout << ":(" << '\n'; else cout << ":)" << '\n' << ans.sc << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...