#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
#define MAX 101010
#define MOD 1000000007
#define ln '\n'
ll mp[101][101];
ll vis[101][101];
pll dir[4];
ll R, S;
char arr[4] = { 'N', 'E', 'S', 'W' };
bool c(ll x, ll y) {
return (1 <= x && x <= R) && (1 <= y && y <= S);
}
void init() {
ll i, j;
for (i = 1; i <= R; i++) {
for (j = 1; j <= S; j++) vis[i][j] = 0;
}
}
ll chk(ll x, ll y) {
if (vis[x][y]) return 0;
vis[x][y] = 1;
if (!c(x, y)) return 0;
if (mp[x][y] == -1) return 0;
if (mp[x][y] >= 4) return 1;
ll res = chk(x + dir[mp[x][y]].first, y + dir[mp[x][y]].second);
if (res) return res + 1;
else return 0;
}
signed main() {
cin >> R >> S;
ll i, j;
dir[0] = { -1, 0 };
dir[1] = { 0, 1 };
dir[2] = { 1, 0 };
dir[3] = { 0, -1 };
vector<string> input;
for (i = 1; i <= R; i++) {
string s;
cin >> s;
input.push_back(s);
}
map<char, ll> asdf;
asdf['.'] = -1;
asdf['^'] = 0;
asdf['>'] = 1;
asdf['v'] = 2;
asdf['<'] = 3;
asdf['o'] = 4;
asdf['x'] = 5;
pll st, en;
for (i = 1; i <= R; i++) {
for (j = 1; j <= S; j++) {
mp[i][j] = asdf[input[i - 1][j - 1]];
if (mp[i][j] == 4) st = { i, j };
}
}
char ans = 'Z';
ll mn = 101010101010;
ll res;
for (i = 0; i < 4; i++) {
init();
mp[st.first][st.second] = i;
res = chk(st.first, st.second);
if (res) {
if (res < mn||(res==mn&&ans>arr[i])) {
mn = res;
ans = arr[i];
}
}
}
if (ans == 'Z') {
cout << ":(" << ln;
return 0;
}
cout << ":)" << ln;
cout << ans << ln;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
460 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
404 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |