#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef __int128 vll;
typedef unsigned __int128 uvll;
ll _i=0;
#define ffn(x) _i=x
#define llll pair<ll , ll>
#define stitr set<ll>::iterator
#define fora(y,x) for(ll y=_i;x>y;y++)
#define pb push_back
#define pf push_front
#define debu cout << "hello\n"
#define fi first
#define sec second
#define all(a) a.begin() , a.end()
const ll limit = 1e13 + 7;
const ll ous=1e6 + 5;
const ll dx[4] = {1 , -1 , 0 , 0} , dy[4] = {0,0,-1,1};
string h[105];ll n , m;
ll fun(llll x){
vector<vector<ll>> vis(105 , vector<ll>(105 , 0));
ll o = 0 , kd = 0;
while(x.fi >-1 && x.fi < n && x.sec > -1 && x.sec < n && h[x.fi][x.sec] != '.' && h[x.fi][x.sec] != 'o' && vis[x.fi][x.sec] == 0){
vis[x.fi][x.sec] = 1;
o++;
if(h[x.fi][x.sec] == 'x'){
kd = 1;
break;
}
if(h[x.fi][x.sec] == 'v'){
x.fi++;
}
else if(h[x.fi][x.sec] == '>'){
x.sec++;
}
else if(h[x.fi][x.sec] == '<'){
x.sec--;
}
else if(h[x.fi][x.sec] == '^'){
x.fi--;
}
}
return (kd==1 ?o :limit);
}
void solve(){
cin >> n >> m;
fora(i,n){
cin >> h[i];
}
llll loc;
fora(i,n){
fora(j,m){
if(h[i][j] == 'o'){
loc = {i , j};
break;
}
}
}
llll mx = {limit , limit};
fora(i,4){
ll z =fun({loc.fi + dx[i] , loc.sec + dy[i]});
//cout << z << "\n";
if(z < mx.fi){
mx.fi = z;mx.sec = i+1;
}
}
if(mx.fi == limit){
cout << ":(\n";
return;
}
cout << ":)\n";
if(mx.sec == 1){
cout << "S\n";
}
else if(mx.sec == 2){
cout << "N\n";
}
else if(mx.sec == 3){
cout << "W\n";
}
else if(mx.sec == 4){
cout << "E\n";
}
return;
}
signed main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);
ll t=1;
//cin >> t;
while(t--){
solve();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |