#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];
pll dir[4];
ll R, S;
bool c(ll x, ll y) {
return (1 <= x && x <= R) && (1 <= y && y <= S);
}
bool chk(ll x, ll y) {
if (!c(x, y)) return 0;
if (mp[x][y] == -1) return 0;
if (mp[x][y] >= 4) return 1;
return chk(x + dir[mp[x][y]].first, y + dir[mp[x][y]].second);
}
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 };
}
}
ll ans = -1;
mp[st.first][st.second] = 0;
if (chk(st.first, st.second)) ans = 0;
mp[st.first][st.second] = 1;
if (chk(st.first, st.second)) ans = 1;
mp[st.first][st.second] = 2;
if (chk(st.first, st.second)) ans = 2;
mp[st.first][st.second] = 3;
if (chk(st.first, st.second)) ans = 3;
if (ans == -1) {
cout << ":(" << ln;
return 0;
}
cout << ":)" << ln;
if (ans == 0) cout << 'N' << ln;
if (ans == 1) cout << 'E' << ln;
if (ans == 2) cout << 'S' << ln;
if (ans == 3) cout << 'W' << ln;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1060 ms |
332 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1078 ms |
204 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |