제출 #525037

#제출 시각아이디문제언어결과실행 시간메모리
525037MOUF_MAHMALATPatkice (COCI20_patkice)C++14
50 / 50
1 ms384 KiB
#include<bits/stdc++.h>
#define all(s) s.begin(),s.end()
#define F first
#define S second
using namespace std;
typedef int ll;
ll n,m,x,y;
char c[109][109];
pair<ll,char>ans;
ll go(ll i,ll j)
{
    if(c[i][j]=='x')
        return 0;
    if(c[i][j]=='.'||c[i][j]=='o')
        return 1e9;
    if(c[i][j]=='>')
        return go(i,j+1)+1;
    if(c[i][j]=='<')
        return go(i,j-1)+1;
    if(c[i][j]=='^')
        return go(i-1,j)+1;
    return go(i+1,j)+1;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    cin>>n>>m;
    for(ll i=0; i<n; i++)
        for(ll j=0; j<m; j++)
        {
            cin>>c[i][j];
            if(c[i][j]=='o')
                x=i,y=j;
        }
    ans.F=1e9;
    ans=min({go(x-1,y),'N'},ans);
    ans=min({go(x+1,y),'S'},ans);
    ans=min({go(x,y+1),'E'},ans);
    ans=min({go(x,y-1),'W'},ans);
    if(ans.F>=1e9)
        cout<<":(";
    else
        cout<<":)\n"<<ans.S;
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...