#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define endl "\n"
#define int long long
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
/* stuff you should look for
* int overflow, array bounds
* special cases (n=1?)
* do smth instead of nothing and stay organized
* WRITE STUFF DOWN
* DON'T GET STUCK ON ONE APPROACH
* SIMPLIFY THE PROBLEM
* READ THE STATEMENT CAREFULLY
!!! if there is an specified/interesting smth(i.e. constraint) in the statement,
then you must be careful about that
*/
vector<string> ar;
int ok=0,d=0;
void dfs(int i,int j){
if(ar[i][j]=='.') return;
if(ar[i][j]=='x'){
ok=1;
return;
}
d++;
if(ar[i][j]=='>') dfs(i,j+1);
else if(ar[i][j]=='<') dfs(i,j-1);
else if(ar[i][j]=='v') dfs(i+1,j);
else dfs(i-1,j);
}
void solve(){
ar.pb("");
int n,m;
cin >> n >> m;
int a = 0 , b = 0;
for(int i=1;i<=n;i++){
string s;
cin >> s;
s = " " + s;
ar.pb(s);
for(int j=1;j<=m;j++){
if(ar[i][j]=='o'){
a = i;
b = j;
break;
}
}
}
vector<pair<int,char>> v;
ok=d=0;
dfs(a,b+1);
if(ok) v.pb({d,'E'});
ok=d=0;
dfs(a-1,b);
if(ok) v.pb({d,'N'});
d=ok=0;
dfs(a+1,b);
if(ok) v.pb({d,'S'});
d=ok=0;
dfs(a,b-1);
if(ok) v.pb({d,'W'});
if(v.empty()){
cout << ":(\n";
return;
}
cout << ":)\n";
sort(all(v));
cout << v[0].second << endl;
}
int32_t main(){
cin.tie(0); ios::sync_with_stdio(0);
int t=1;//cin >> t;
while(t--) solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Execution timed out |
1061 ms |
348 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
856 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Execution timed out |
1058 ms |
348 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |