Submission #333872

#TimeUsernameProblemLanguageResultExecution timeMemory
333872wiwihoPatkice (COCI20_patkice)C++14
50 / 50
1 ms492 KiB
#include <bits/stdc++.h> #define pii pair<int, int> #define mp make_pair #define F first #define S second using namespace std; typedef long long ll; vector<string> a; const ll MAX = 2147483647; int calc(int x, int y){ int ans = 0; while(true){ if(a[x][y] == '<') y--; else if(a[x][y] == '>') y++; else if(a[x][y] == '^') x--; else if(a[x][y] == 'v') x++; else break; ans++; } if(a[x][y] == 'x') return ans + 1; else return MAX; } int main(){ ios_base::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; a.resize(n); pii o; for(int i = 0; i < n; i++){ cin >> a[i]; for(int j = 0; j < m; j++){ if(a[i][j] == 'o') o = mp(i, j); } } vector<pii> dir = {mp(0, 1), mp(-1, 0), mp(1, 0), mp(0, -1)}; vector<char> c = {'E', 'N', 'S', 'W'}; int ans = MAX; char ansp = '.'; for(int i = 0; i < 4; i++){ int tmp = calc(o.F + dir[i].F, o.S + dir[i].S); if(tmp < ans){ ans = tmp; ansp = c[i]; } } if(ans == MAX){ cout << ":(\n"; return 0; } cout << ":)\n"; cout << ansp << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...