이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
const int N = 100 + 10;
char M[N][N];
int cnt = 0, ans = 1e9;
bool found = false;
string out = ":(\n";
void dfs(int x, int y)
{
cnt++;
if(M[x][y] == 'x')
{
found = true;
return;
}
if(M[x][y] == '^')
dfs(x - 1, y);
if(M[x][y] == 'v')
dfs(x + 1, y);
if(M[x][y] == '>')
dfs(x, y + 1);
if(M[x][y] == '<')
dfs(x, y - 1);
}
int main()
{
int n, m;
cin >> n >> m;
for(int i = 0; i < n; i ++)
for(int j = 0; j < m ; j ++)
cin >> M[i][j];
pair<int,int> O;
for(int i = 0; i < n; i++)
for(int j = 0; j < m; j ++)
if(M[i][j] == 'o')
O = {i, j};
dfs(O.first, O.second + 1);
if(found) {
if(ans > cnt)
out = ":)\nE\n", ans = cnt;
}
cnt = 0, found = false;
dfs(O.first - 1, O.second);
if(found) {
if(ans > cnt)
out = ":)\nN\n", ans = cnt;
}
cnt = 0, found = false;
dfs(O.first, O.second - 1);
if(found) {
if(ans > cnt)
out = ":)\nW\n", ans = cnt;
}
cnt = 0, found = false;
dfs(O.first + 1, O.second);
if(found) {
if(ans > cnt)
out = ":)\nS\n", ans = cnt;
}
cout << out;
return 0;
}
// ENSW
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |