제출 #1169454

#제출 시각아이디문제언어결과실행 시간메모리
1169454ChocoPatkice (COCI20_patkice)C++20
50 / 50
0 ms328 KiB
#include<bits/stdc++.h>
using namespace std;
#define Study ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define ull unsigned long long
#define pb push_back
#define ff first 
#define ss second
#define ins insert
#define all(x) x.begin(),x.end()
#define fori(x,y,z) for(ll x=y;x<=z;x++)
const ll INF=1e9;
const ll sz=1e2+10;
const ll mod=1e9+7;
vector<vector<char>>c(sz,vector<char>(sz,0));
ll dfs(ll x,ll y,ll cr){
    if(c[x][y]=='.' || c[x][y]=='o'){
        return INF;
    }
    if(c[x][y]=='x'){
        return cr;
    }
    if(c[x][y]=='<'){
        return dfs(x,y-1,cr+1);
    }
    else if(c[x][y]=='^'){
        return dfs(x-1,y,cr+1);
    }
    else if(c[x][y]=='>'){
        return dfs(x,y+1,cr+1);
    }
    else{
        return dfs(x+1,y,cr+1);
    }
}
void work(){
    ll n,m;
    cin>>n>>m;
    ll x,y;
    fori(i,1,n){
        string s;
        cin>>s;
        fori(j,0,m-1){
        c[i][j+1]=s[j];
        if(c[i][j+1]=='o'){
            x=i;y=j+1;
        }
        }
    }
    ll ans=INF;
    char node;
    ll cr=dfs(x,y+1,0);
    if(cr<ans){
        ans=cr;
        node='E';
    }
    cr=dfs(x-1,y,0);
    if(cr<ans){
        ans=cr;
        node='N';
    }
    cr=dfs(x+1,y,0);
    if(cr<ans){
        ans=cr;
        node='S';
    }
    cr=dfs(x,y-1,0);
    if(cr<ans){
        ans=cr;
        node='W';
    }
    if(ans<INF){
        cout<<":)\n"<<node;
    }
    else
    cout<<":(";
}
int main(){
    Study;
    ll t=1;
    //cin>>t;
    while(t--){
        work();
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...