#include <bits/stdc++.h>
using namespace std;
int r, s, col, row, mark[105][105];
pair<int, int> dir[4] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
pair<char, int> cevap;
char d[105][105];
pair<bool, int> check(int x, int y, int step){
if(mark[x][y]){
return {false, 0};
}
mark[x][y] = 1;
char ch = d[x][y];
pair<bool, int> ans;
switch (ch)
{
case 'x':
return {true, step};
break;
case '>':
ans = check(x, y + 1, step + 1);
break;
case '<':
ans = check(x, y - 1, step + 1);
break;
case 'v':
ans = check(x + 1, y, step + 1);
break;
case '^':
ans = check(x - 1, y, step + 1);
break;
default:
return {false, 0};
break;
}
return ans;
}
int main(){
cevap.second = INT_MAX;
cin >> r >> s;
for (int i = 0; i < r; i++)
{
for (int j = 0; j < s; j++)
{
cin >> d[i][j];
if(d[i][j] == 'o'){
row = i;
col = j;
}
}
}
for (int i = 0; i < 4; i++)
{
pair<bool, int> temp = check(row + dir[i].first, col + dir[i].second, 1);
if(temp.first && temp.second < cevap.second){
cevap.second = temp.second;
switch (i)
{
case 0:
cevap.first = 'S';
break;
case 1:
cevap.first = 'N';
break;
case 2:
cevap.first = 'E';
break;
default:
cevap.first = 'W';
break;
}
}
memset(mark, 0, sizeof(mark));
}
if(cevap.first){
cout << ":)\n" << cevap.first;
}else{
cout << ":(";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |