This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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];
if(valid(nx, ny) && !seen[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 (stderr)
patkice.cpp: In function 'int main()':
patkice.cpp:56:6: warning: 'oj' may be used uninitialized in this function [-Wmaybe-uninitialized]
56 | dfs(oi, oj);
| ~~~^~~~~~~~
patkice.cpp:56:6: warning: 'oi' may be used uninitialized in this function [-Wmaybe-uninitialized]
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |