#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define ll long long
#define ff first
#define ss second
#define int ll
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define pb push_back
#define pii pair <int, int>
using namespace std;
const int inf = 1e15;
const int mod = 1e9+7;
const int N = 2e5+100;
int n, m;
vector < string > a(N);
int dfs(int x, int y, int d = 0){
if (a[x][y] == 'o' || a[x][y] == 'x' || a[x][y] == '.'){
if (a[x][y] == 'x') return d;
return inf;
}
if (a[x][y] == '>') return dfs(x, y+1, d+1);
if (a[x][y] == '<') return dfs(x, y-1, d+1);
if (a[x][y] == '^') return dfs(x-1, y, d+1);
if (a[x][y] == 'v') return dfs(x+1, y, d+1);
}
void solve(){
cin >> n >> m;
for (int i = 0; i < n; ++i) cin >> a[i];
pii start;
for (int i = 0; i < n; ++i)
for (int j = 0; j < m; ++j)
if (a[i][j] == 'o') start = {i, j};
vector <int> ans(4, inf);
ans[0] = dfs(start.ff, start.ss+1);
ans[3] = dfs(start.ff, start.ss-1);
ans[1] = dfs(start.ff-1, start.ss);
ans[2] = dfs(start.ff+1, start.ss);
int mx = *min_element(all(ans));
if (mx == inf){
cout << ":(";
return;
}
cout << ":)\n";
if (ans[0] == mx) cout << "E";
else if (ans[1] == mx) cout << "N";
else if (ans[2] == mx) cout << "S";
else cout << "W";
}
signed main(){
ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int tt = 1;
//cin >> tt;
while (tt--){
solve();
cout << '\n';
}
}
Compilation message
patkice.cpp: In function 'long long int dfs(long long int, long long int, long long int)':
patkice.cpp:28:1: warning: control reaches end of non-void function [-Wreturn-type]
28 | }
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
6476 KB |
Output is correct |
2 |
Correct |
5 ms |
6484 KB |
Output is correct |
3 |
Correct |
3 ms |
6596 KB |
Output is correct |
4 |
Correct |
4 ms |
6476 KB |
Output is correct |
5 |
Correct |
3 ms |
6604 KB |
Output is correct |
6 |
Correct |
4 ms |
6604 KB |
Output is correct |
7 |
Correct |
3 ms |
6476 KB |
Output is correct |
8 |
Correct |
3 ms |
6476 KB |
Output is correct |
9 |
Correct |
3 ms |
6476 KB |
Output is correct |
10 |
Correct |
3 ms |
6476 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
6476 KB |
Output is correct |
2 |
Correct |
4 ms |
6604 KB |
Output is correct |
3 |
Correct |
4 ms |
6476 KB |
Output is correct |
4 |
Correct |
3 ms |
6476 KB |
Output is correct |
5 |
Correct |
3 ms |
6476 KB |
Output is correct |
6 |
Correct |
3 ms |
6476 KB |
Output is correct |
7 |
Correct |
4 ms |
6588 KB |
Output is correct |
8 |
Correct |
4 ms |
6596 KB |
Output is correct |
9 |
Correct |
3 ms |
6476 KB |
Output is correct |
10 |
Correct |
4 ms |
6604 KB |
Output is correct |
11 |
Correct |
4 ms |
6596 KB |
Output is correct |
12 |
Correct |
4 ms |
6604 KB |
Output is correct |
13 |
Correct |
3 ms |
6476 KB |
Output is correct |
14 |
Correct |
3 ms |
6476 KB |
Output is correct |
15 |
Correct |
4 ms |
6592 KB |
Output is correct |
16 |
Correct |
4 ms |
6476 KB |
Output is correct |
17 |
Correct |
3 ms |
6476 KB |
Output is correct |
18 |
Correct |
4 ms |
6476 KB |
Output is correct |
19 |
Correct |
3 ms |
6476 KB |
Output is correct |
20 |
Correct |
3 ms |
6476 KB |
Output is correct |