/*
* ## ##### #### #### # # ####
* # # # # # # # # # # # #
* # # ##### # # # # # # #
* ###### # # # # # # ## # # #
* # # # # # # # # ## ## # #
* # # ##### #### #### # # ####
*/
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair <int, int>
#define X first
#define Y second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define info() cerr << __PRETTY_FUNCTION__ << ": " << __LINE__ << endl
void abc() {cerr << endl;}
template <typename T, typename ...U> void abc(T a, U ...b) {
cerr << a << ' ', abc(b...);
}
template <typename T> void printv(T l, T r) {
while (l != r) cout << *l << " \n"[++l == r];
}
template <typename A, typename B> istream& operator >> (istream& o, pair<A, B> &a) {
return o >> a.X >> a.Y;
}
template <typename A, typename B> ostream& operator << (ostream& o, pair<A, B> a) {
return o << '(' << a.X << ", " << a.Y << ')';
}
template <typename T> ostream& operator << (ostream& o, vector<T> a) {
bool is = false;
for (T i : a) {o << (is ? ' ' : '{'), is = true, o << i;}
return o << '}';
}
template <typename T> struct vv : vector <vector <T>> {
vv(int n, int m, T v) : vector <vector <T>> (n, vector <T>(m, v)) {}
vv() {}
};
template <typename T> struct vvv : vector <vv <T>> {
vvv(int n, int m, int k, T v) : vector <vv <T>> (n, vv <T>(m, k, v)) {}
vvv() {}
};
#ifdef Doludu
#define test(args...) info(), abc("[" + string(#args) + "]", args)
#define owo void(0)
#else
#define test(args...) void(0)
#define owo ios::sync_with_stdio(false); cin.tie(0)
#endif
const int mod = 1e9 + 7, N = 200001, logN = 18, K = 1000;
int main () {
owo;
int n, m, x, y;
cin >> n >> m;
vector <string> s(n);
for (int i = 0; i < n; ++i) {
cin >> s[i];
for (int j = 0; j < m; ++j) if (s[i][j] == 'o') x = i, y = j;
}
auto walk = [&](int x, int y) {
vv <bool> vis(n, m, false);
int t = 0;
while (true) {
if (vis[x][y]) break;
vis[x][y] = true;
if (s[x][y] == 'x') return t;
else if (s[x][y] == '<') y--;
else if (s[x][y] == '>') y++;
else if (s[x][y] == 'v') x++;
else if (s[x][y] == '^') x--;
else break;
t++;
}
return 1 << 30;
};
pair <int, char> ans = mp(1 << 29, '.');
if (y + 1 < m && walk(x, y + 1) < ans.X) {
ans = min(ans, mp(walk(x, y + 1), 'E'));
}
if (x && walk(x - 1, y) < ans.X) {
ans = min(ans, mp(walk(x - 1, y), 'N'));
}
if (x + 1 < n && walk(x + 1, y) < ans.X) {
ans = min(ans, mp(walk(x + 1, y), 'S'));
}
if (y && walk(x, y - 1) < ans.X) {
ans = min(ans, mp(walk(x, y - 1), 'W'));
}
if (ans.Y != '.') {
cout << ":)\n" << ans.Y << '\n';
} else {
cout << ":(\n";
}
}
Compilation message
patkice.cpp: In function 'int main()':
patkice.cpp:91:18: warning: 'y' may be used uninitialized in this function [-Wmaybe-uninitialized]
91 | if (y && walk(x, y - 1) < ans.X) {
| ~~~~^~~~~~~~~~
patkice.cpp:85:18: warning: 'x' may be used uninitialized in this function [-Wmaybe-uninitialized]
85 | if (x && walk(x - 1, y) < ans.X) {
| ~~~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
308 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
204 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
0 ms |
204 KB |
Output is correct |