이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,char> ci;
vector<string> vs;
const ll MAX=1e9;
ll n,m;
ll voyage(ll a,ll b){
if(a<0 or b<0 or a>=n or b>=m) return MAX;
ll ans=0;
if(vs[a][b]=='.' or vs[a][b]=='o') return MAX;
if(vs[a][b]=='x') return 0;
if(vs[a][b]=='>')
ans+=(voyage(a,b+1)+1);
if(vs[a][b]=='<')
ans+=(voyage(a,b-1)+1);
if(vs[a][b]=='^')
ans+=(voyage(a-1,b)+1);
if(vs[a][b]=='v')
ans+=(voyage(a+1,b)+1);
return ans;
}
int main(){
cin>>n>>m;
ll a,b;
a=-1; b=-1;
for(ll i=0;i<n;i++){
string x;
cin>>x;
vs.push_back(x);
if(a==-1){
for(ll j=0;j<m;j++){
if(x[j]=='o'){
a=i; b=j;
break;
}
}
}
}
vector<ci>aux;
ll w,e,s,no;
w=voyage(a,b-1)+1;
e=voyage(a,b+1)+1;
s=voyage(a+1,b)+1;
no=voyage(a-1,b)+1;
ll ma=MAX+MAX;
ma=min(min(w,e),min(no,s));
// cout<<w<<" "<<e<<" "<<no<<" "<<s<<endl;
if(ma>=MAX){
cout<<":(\n";
}
else{
aux.push_back(ci(w,'W'));
aux.push_back(ci(e,'E'));
aux.push_back(ci(s,'S'));
aux.push_back(ci(no,'N'));
cout<<":)\n";
sort(aux.begin(),aux.end());
/*for(int i=0;i<aux.size();i++){
cout<<
}*/
cout<<aux[0].second<<endl;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |