#include <bits/stdc++.h>
using namespace std;
long long h[7] = {0, 1, 0, -1, 0};
long long mark[1005][1005];
char pre[1005][1005];
bool valid(long long i, char c)
{
if (i == 0 && c == '>') return true;
if (i == 1 && c == 'v') return true;
if (i == 2 && c == '<') return true;
if (i == 3 && c == '^') return true;
return false;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long r, s;
cin >> r >> s;
char a[r + 1][s + 1];
for (int i = 1; i <= r; i++)
{
for (int j = 1; j <= s; j++)
{
cin >> a[i][j];
}
}
deque <pair<long long, long long>> dq;
for (int i = 1; i <= r; i++)
{
for (int j = 1; j <= s; j++)
{
if (a[i][j] == 'o')
{
dq.push_back(make_pair(i, j));
mark[i][j] = 1;
}
}
}
bool check = false;
while (!dq.empty())
{
pair <long long, long long> u = dq.front();
dq.pop_front();
if (a[u.first][u.second] == 'x')
{
check = true;
break;
}
for (int i = 0; i <= 3; i++)
{
long long newx = u.first + h[i], newy = u.second + h[i + 1];
if (!mark[newx][newy] && newx <= r && newy <= s && newx >= 1&& newy >= 1 && a[newx][newy] != '.')
{
if (a[u.first][u.second] == 'o')
{
if (i == 0) pre[newx][newy] = 'E';
if (i == 1) pre[newx][newy] = 'S';
if (i == 2) pre[newx][newy] = 'W';
if (i == 3) pre[newx][newy] = 'N';
dq.push_back(make_pair(newx, newy));
}
else
{
if (valid(i, a[u.first][u.second]))
{
dq.push_back(make_pair(newx, newy));
mark[newx][newy] = 1;
pre[newx][newy] = pre[u.first][u.second];
}
}
}
}
}
long long posx, posy;
for (int i = 1; i <= r; i++)
{
for (int j = 1; j <= s; j++)
{
if (a[i][j] == 'x')
{
posx = i;
posy = j;
break;
}
}
}
if (check) cout << ":)" << "\n" << pre[posx][posy] << "\n";
else cout << ":(";
return 0;
}
Compilation message
patkice.cpp: In function 'int main()':
patkice.cpp:92:54: warning: 'posy' may be used uninitialized in this function [-Wmaybe-uninitialized]
92 | if (check) cout << ":)" << "\n" << pre[posx][posy] << "\n";
| ~~~~~~~~~~~~~~^
patkice.cpp:92:54: warning: 'posx' may be used uninitialized in this function [-Wmaybe-uninitialized]
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2392 KB |
Output is correct |
9 |
Correct |
1 ms |
2408 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2392 KB |
Output is correct |
5 |
Correct |
1 ms |
2392 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2392 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
2 ms |
2396 KB |
Output is correct |
18 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |