Submission #1163278

#TimeUsernameProblemLanguageResultExecution timeMemory
1163278mnbvcxz123Patkice (COCI20_patkice)C++20
50 / 50
0 ms396 KiB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
int const N=105;
int const inf=1e9+7;
int n,m,sx,sy,ex,ey;
int a[4]={0,1,0,-1};
int b[4]={1,0,-1,0};
string di="ESWN";
char s[N][N];
int dfs(int x,int y,int d=1){
	if (x < 1 or y < 1 or x > n or y > m)
		return inf;

    if (s[x][y] == 'x')
    	return d;
    if (s[x][y] == '.' or s[x][y] == 'o')
    	return inf;

    if (s[x][y] == '>')
    	return dfs(x, y + 1, d + 1);
    if (s[x][y] == '<')
    	return dfs(x, y - 1, d + 1);
    if (s[x][y] == 'v')
    	return dfs(x + 1, y, d + 1);
    if (s[x][y] == '^')
    	return dfs(x - 1, y, d + 1);
    return 0;
}

int main(){
	cin >> n >> m;
    for (int i = 1; i <= n; i ++){
        for (int j = 1; j <= m; j ++){
            cin >> s[i][j];
            if (s[i][j] == 'x')
                ex = i, ey = j;
            else if (s[i][j] == 'o')
                sx = i, sy = j;
        }
    }
    pair<int,char> p={inf,'a'};
    for(int i=0;i<4;i++)
    	p=min(p,{dfs(sx+a[i],sy+b[i]),di[i]});
    if(p.first==inf){
    	cout<<":("<<endl;
    	return 0;
    }
    cout<<":)"<<endl;
    cout<<p.second<<endl;
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...