이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |