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;
#define ll long long
#define endl '\n'
const ll MOD = 1e9+7;
const ll INF = 1e16;
const ll MAX = 2 * 1e5;
int n,m;
char arr[101][101];
int DFS(int x, int y){
if(arr[x][y] == 'o' || arr[x][y] == '.') return -1e8;
if(arr[x][y] == 'x') return 0;
if(arr[x][y] == '>') return DFS(x, y+1) + 1;
if(arr[x][y] == '<') return DFS(x, y-1) + 1;
if(arr[x][y] == 'v') return DFS(x + 1, y) + 1;
return DFS(x - 1, y) + 1;
}
void solve(){
cin>>n>>m;
pair<int,int> start;
for(int i = 0; i < n; i++){
for(int j = 0; j < m; j++){
cin>>arr[i][j];
if(arr[i][j] == 'o') start = {i,j};
}
}
vector<pair<int, char>> ans;
int temp = DFS(start.first, start.second + 1);
if(temp >= 0)
ans.push_back({temp, 'E'});
temp = DFS(start.first, start.second - 1);
if(temp >= 0)
ans.push_back({temp, 'W'});
temp = DFS(start.first - 1, start.second);
if(temp >= 0)
ans.push_back({temp, 'N'});
temp = DFS(start.first + 1, start.second);
if(temp >= 0)
ans.push_back({temp, 'S'});
if(ans.size() == 0){
cout<<":(";
}else{
sort(ans.begin(), ans.end());
cout<<":)"<<endl;
cout<<ans[0].second;
}
}
int main()
{
cin.tie(NULL);
ios::sync_with_stdio(NULL);
int t = 1;
//cin>>t;
int temp = t;
while(t--){
//cout<<"Case #"<<temp - t<<" > "<<endl;
solve();
cout<<endl;
}
cout.flush();
}
Compilation message (stderr)
patkice.cpp: In function 'int main()':
patkice.cpp:76:9: warning: unused variable 'temp' [-Wunused-variable]
76 | int temp = t;
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |