제출 #315734

#제출 시각아이디문제언어결과실행 시간메모리
315734DanerZeinPatkice (COCI20_patkice)C++14
50 / 50
1 ms384 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...