제출 #394555

#제출 시각아이디문제언어결과실행 시간메모리
394555couplefirePatkice (COCI20_patkice)C++17
0 / 50
1 ms332 KiB
#include <bits/stdc++.h> using namespace std; #define MAXN 105 #define INF 1000000009 int n, m; array<int, 2> grid[MAXN][MAXN]; map<char, array<int, 2>> mp; pair<int, char> ans = {INF, 'a'}; int dfs(int x, int y){ if(grid[x][y] == array<int, 2>{0, 0} || grid[x][y] == array<int, 2>{-INF, -INF}) return INF; if(grid[x][y] == array<int, 2>{INF, INF}) return 0; return dfs(x+grid[x][y][0], y+grid[x][y][1])+1; } int main(){ // freopen("a.in", "r", stdin); ios_base::sync_with_stdio(false); cin.tie(0); cin >> n >> m; mp['^'] = {-1, 0}; mp['v'] = {1, 0}; mp['<'] = {0, -1}; mp['>'] = {0, 1}; mp['o'] = {-INF, -INF}; mp['.'] = {0, 0}; mp['x'] = {INF, INF}; for(int i = 0; i<n; i++){ string s; cin >> s; for(int j = 0; j<n; j++) grid[i][j] = mp[s[j]]; } for(int i = 0; i<n; i++){ for(int j = 0; j<n; j++){ if(grid[i][j] != array<int, 2>{-INF, -INF}) continue; ans = min(ans, {dfs(i+1, j), 'S'}); ans = min(ans, {dfs(i-1, j), 'N'}); ans = min(ans, {dfs(i, j+1), 'E'}); ans = min(ans, {dfs(i, j-1), 'W'}); } } if(ans.first >= INF){ cout << ":(" << endl; } else{ cout << ":)" << endl; cout << ans.second << endl; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...