답안 #470311

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
470311 2021-09-03T13:09:27 Z mychecksedad Patkice (COCI20_patkice) C++17
50 / 50
1 ms 332 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
const int N = 110, F = 1e9+7;


int n, m, sx, sy;
char arr[N][N];
int dfs(int x, int y){
	if(x == 0 || x == n + 1 || y == 0 || y == m + 1 || arr[x][y] == '.' || arr[x][y] == 'o') return F;
	if(arr[x][y] == 'x') return 1;
	int ans = 0;
	if(arr[x][y] == '>'){
		ans = dfs(x, y + 1);
	}
	if(arr[x][y] == '<'){	
		ans = dfs(x, y - 1);
	}
	if(arr[x][y] == '^'){
		ans = dfs(x - 1, y);
	}
	if(arr[x][y] == 'v'){
		ans = dfs(x + 1, y);
	}
	return min(ans + 1, F);
}
int main(){
	cin.tie(0); ios::sync_with_stdio(0);
	cin >> n >> m;
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
			cin >> arr[i][j];
			if(arr[i][j] == 'o'){
				sx = i, sy = j;
			}
		}
	}
	int ans1 = dfs(sx, sy + 1);
	int ans2 = dfs(sx, sy - 1);
	int ans3 = dfs(sx - 1, sy);
	int ans4 = dfs(sx + 1, sy);
	int r = min({ans1, ans2, ans3, ans4});
	if(r==F){
		cout << ":(";
	}else{
		cout << ":)\n";
		if(r == ans1) cout << "E";
		else if(r == ans3) cout << "N";
		else if(r == ans4) cout << "S";
		else if(r == ans2) cout << "W";
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct