#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define all(a) a.begin(),a.end()
#define pb push_back
using namespace std;
struct DSU{
vector<int>par;
int n;
DSU (int _n)
{
n = _n;
par.assign(n, -1);
}
int _find(int v)
{
if(par[v] < 0)
return v;
return _find(par[v]);
}
void _union(int a, int b)
{
a = par[a];
b = par[b];
if(a != b)
{
par[a] += par[b];
par[b] = a;
}
}
};
const int N = 500;
char g[N][N];
int dis[N][N] = {-1};
int n,m;
bool av(int i,int j)
{
if(i >= 0 and i < n and j >= 0 and j < m and g[i][j] != '.' and dis[i][j] == -1)
return true;
return false;
}
void bfs(int a,int b)
{
queue<pair<int,int>>q;
q.push({a,b});
dis[a][b] = 0;
while(!q.empty())
{
int c = q.front().first;
int d = q.front().second;
if(dis[c][d] > 0)
return;
if(g[c][d] == '>' and av(c,d+1))
q.push({c,d + 1}), dis[c][d + 1] = dis[c][d] + 1;
if(g[c][d] == '<' and av(c,d-1))
q.push({c,d - 1}), dis[c][d - 1] = dis[c][d] + 1;
if(g[c][d] == '^' and av(c - 1, d))
q.push({c - 1, d}), dis[c - 1][d] = dis[c][d] + 1;
if(g[c][d] == 'v' and av(c + 1,d))
q.push({c + 1,d}), dis[c + 1][d] = dis[c][d] + 1;
}
}
void _()
{
cin >> n >> m;
pair<int,int>st,en;
for(int i = 0; i < n; ++i)
{
for(int j = 0; j < m; ++j)
{
cin >> g[i][j];
if(g[i][j] == 'o')
st = {i, j};
if(g[i][j] == 'x')
en = {i, j};
}
}
int l = en.first, r = en.second;
if(dis[l][r] == -1)
{
cout << ":( " << endl;
return;
}
cout << ":) " << endl;
if(en.second > st.second)
cout << "S" << endl;
else if(en.second < st.second)
cout << "N" << endl;
else if(en.first > st.first)
cout << "E" << endl;
else
cout << "W" << endl;
}
main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
//USACO("");
int tc = 1;
while(tc--)
_();
}
Compilation message
patkice.cpp:105:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
105 | main()
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |