This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#ifndef _LOCAL
//#pragma GCC optimize("O3,Ofast")
#else
#pragma GCC optimize("O0")
#endif
template<typename t> inline void umin(t &a, const t b) {a = min(a, b);}
template<typename t> inline void umax(t &a, const t b) {a = max(a, b);}
typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;
ll time() {return chrono::system_clock().now().time_since_epoch().count();}
mt19937 rnd(time());
#define ft first
#define sd second
#define len(f) int((f).size())
#define bnd(f) (f).begin(), (f).end()
#define _ <<' '<<
const int inf = 1e9 + 5;
const ll inf64 = 4e18 + 5;
const int md = 998244353;
namespace MD {
void add(int &a, const int b) {if((a += b) >= md) a -= md;}
void sub(int &a, const int b) {if((a -= b) < 0) a += md;}
int prod(const int a, const int b) {return ll(a) * b % md;}
};
int n, m;
const int N = 105;
int opt;
char ans;
string c[N];
int f(int x, int y, char d) {
if(x < 0 || y < 0 || x >= n || y >= m)
return opt + 1;
if(d == '#') d = c[x][y];
if(d == '.') return opt + 1;
if(d == 'v') return 1 + f(x + 1, y + 0, '#');
if(d == '>') return 1 + f(x + 0, y + 1, '#');
if(d == '^') return 1 + f(x - 1, y - 0, '#');
if(d == '<') return 1 + f(x - 0, y - 1, '#');
return 0;
}
void update(char c, int v) {
if(v > opt || (v == opt && c >= ans)) return;
opt = v;
ans = c;
}
void solve() {
cin >> n >> m;
opt = n * m + 5;
int sx, sy;
for(int i = 0; i < n; ++i) {
cin >> c[i];
for(int j = 0; j < m; ++j)
if(c[i][j] == 'o') sx = i, sy = j;
}
update('N', f(sx, sy, '^'));
update('E', f(sx, sy, '>'));
update('S', f(sx, sy, 'v'));
update('W', f(sx, sy, '<'));
if(opt >= n * m) {
cout << ":(\n";
return;
}
cout << ":)\n" << ans << '\n';
}
int main() {
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#ifndef _LOCAL
// freopen("file.in", "r", stdin);
// freopen("file.out", "w", stdout);
#else
system("color a");
freopen("in.txt", "r", stdin);
int t; cin >> t;
while(t--)
#endif
solve();
}
Compilation message (stderr)
patkice.cpp: In function 'void solve()':
patkice.cpp:62:11: warning: 'sy' may be used uninitialized in this function [-Wmaybe-uninitialized]
62 | update('N', f(sx, sy, '^'));
| ~~~~~~^~~~~~~~~~~~~~~~~~~~~
patkice.cpp:62:11: warning: 'sx' may be used uninitialized in this function [-Wmaybe-uninitialized]
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |