#include "bits/stdc++.h"
using namespace std;
#define int long long
#define mp make_pair
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define nbits(x) __builtin_popcount(x)
#define gcd(x, y) __gcd(x, y)
#define SYNC_OFF ios::sync_with_stdio(0); cin.tie(0);
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
const int MOD = 1e9 + 7; // 998244353;
const int N = 300100;
const int INF = 1e15; // 1e18;
const double PI = acos(-1);
const int dx[] = {-1,0,1,0,-1,1,1,-1};
const int dy[] = {0,1,0,-1,1,1,-1,-1};
int powmod(int a, int b, int m = MOD) {
int res = 1;
a %= m; assert(b >= 0);
for (; b; b>>=1) {
if (b & 1) res = res*a % m;
a = a*a % m;
}
return res;
}
int n, m, steps;
char dir;
char a[101][101];
int vis[101][101];
vector<pair<int, char>> ans;
void dfs(int x, int y) {
steps++;
vis[x][y] = 1;
if (a[x][y] == 'x') {
ans.pb({steps, dir});
} else if (a[x][y] == '^') {
dfs(x - 1, y);
} else if (a[x][y] == '>') {
dfs(x, y + 1);
} else if (a[x][y] == 'v') {
dfs(x + 1, y);
} else if (a[x][y] == '<') {
dfs(x, y - 1);
}
}
signed main() {
SYNC_OFF;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> (a[i] + 1);
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (a[i][j] == 'o') {
memset(vis, 0, sizeof vis);
steps = 0, dir = 'N'; dfs(i - 1, j);
memset(vis, 0, sizeof vis);
steps = 0, dir = 'S'; dfs(i + 1, j);
memset(vis, 0, sizeof vis);
steps = 0, dir = 'W'; dfs(i, j - 1);
memset(vis, 0, sizeof vis);
steps = 0, dir = 'E'; dfs(i, j + 1);
}
}
}
sort(all(ans));
if (ans.size() == 0) {
cout << ":(\n";
} else {
cout << ":)\n" << ans[0].second << "\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
492 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
492 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
492 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
492 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
492 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
492 KB |
Output is correct |
11 |
Correct |
1 ms |
492 KB |
Output is correct |
12 |
Correct |
1 ms |
492 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
492 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |