#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] = {0 , -1 , 1 , 0} , dy[4] = {1,0,0,-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 < m && h[x.fi][x.sec] != '.' && h[x.fi][x.sec] != 'o' && vis[x.fi][x.sec] == 0){
vis[x.fi][x.sec] = 1;
if(h[x.fi][x.sec] == 'x'){
kd = 1;
break;
}
o++;
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 << "E\n";
}
else if(mx.sec == 2){
cout << "N\n";
}
else if(mx.sec == 3){
cout << "S\n";
}
else{
cout << "W\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 |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
332 KB |
Output is correct |
9 |
Correct |
0 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
0 ms |
324 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
0 ms |
332 KB |
Output is correct |
16 |
Correct |
0 ms |
332 KB |
Output is correct |
17 |
Correct |
0 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
316 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |