#include<bits/stdc++.h>
using namespace std;
const int N = 100 + 10;
char c;
int n, m, d[] = {-1, 1, 0, 0};
char M[N][N];
bool seen[N][N];
bool valid(int x, int y)
{
return x >= 0 && y >= 0 && x < n && y < m;
}
void dfs(int x, int y)
{
// cerr << x << ' ' << y << endl;
seen[x][y] = true;
if(M[x][y] == 'x')
{
cout << ":)\n";
cout << c << endl;
exit(0);
}
if(M[x][y] == '.')
return;
string s = "^v><";
string D = "NSEW";
for(int i = 0; i < 4; i ++)
{
int nx = x + d[i], ny = y + d[3 - i];
if(M[x][y] == 'o')
{
c = D[i];
for(int i = 0; i < n; i ++)
for(int j = 0; j < m; j ++)
seen[i][j] = false;
seen[x][y] = true;
if(valid(nx, ny))
dfs(nx, ny);
}
else if(s[i] == M[x][y] && valid(nx, ny) && !seen[nx][ny])
dfs(nx, ny);
}
}
int main()
{
cin >> n >> m;
int oi, oj;
for(int i = 0; i < n; i ++)
for(int j = 0; j < m; j++)
{
cin >> M[i][j];
if(M[i][j] == 'o') oi = i, oj = j;
}
dfs(oi, oj);
cout << ":(\n";
return 0;
}
Compilation message
patkice.cpp: In function 'int main()':
patkice.cpp:62:6: warning: 'oj' may be used uninitialized in this function [-Wmaybe-uninitialized]
62 | dfs(oi, oj);
| ~~~^~~~~~~~
patkice.cpp:62:6: warning: 'oi' may be used uninitialized in this function [-Wmaybe-uninitialized]
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |