Submission #804571

# Submission time Handle Problem Language Result Execution time Memory
804571 2023-08-03T09:53:18 Z tlnk07 Patkice (COCI20_patkice) C++17
50 / 50
2 ms 2788 KB
#include<bits/stdc++.h>
using namespace std;

long long n, m, start, finish;
string s;
vector<int> vec[100001];
bool check = 0;
char ans;
pair<int, char> mini = {INT_MAX, '0'};

void dfs(int x, int h)
{
	if(x == finish)
	{
		check = 1;
		if(mini.first > h)	mini = {h, ans};
	}
	if(check)	return;
	for(int c : vec[x])
	{
		if(x == start && h > 0)	return;
		if(x == start)
		{
			check = 0;
			if(c == start + 1)	ans = 'E';
			else if(c == start - m)	ans = 'N';
			else if(c == start + m)	ans = 'S';
			else	ans = 'W';
		}
		dfs(c, h + 1);
	}
}

int main()
{
	cin >> n >> m;
	for(int i = 0; i < n; ++i)
	{
		cin >> s;
		for(int j = 0; j < m; ++j)
		{
			if(s[j] == 'o')
			{
				start = i * m + j + 1;
				if(j < m - 1)	vec[i * m + j + 1].push_back(i * m + j + 2);
				if(i > 0)	vec[i * m + j + 1].push_back(i * m + j - m + 1);
				if(i < n - 1)	vec[i * m + j + 1].push_back(i * m + j + m + 1);
				if(j > 0)	vec[i * m + j + 1].push_back(i * m + j);
			}
			else if(s[j] == 'x')	finish = i * m + j + 1;
			else if(s[j] == 'v')	vec[i * m + j + 1].push_back(i * m + j + m + 1);
			else if(s[j] == '>')	vec[i * m + j + 1].push_back(i * m + j + 2);
			else if(s[j] == '<')	vec[i * m + j + 1].push_back(i * m + j);
			else if(s[j] == '^')	vec[i * m + j + 1].push_back(i * m + j - m + 1);
		}
	}
	dfs(start, 0);
	if(mini.first < INT_MAX)	cout << ":)\n" << mini.second;
	else	cout << ":(";
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 1 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 2 ms 2580 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 1 ms 2644 KB Output is correct
10 Correct 2 ms 2676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 1 ms 2644 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 1 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 1 ms 2644 KB Output is correct
10 Correct 2 ms 2772 KB Output is correct
11 Correct 1 ms 2644 KB Output is correct
12 Correct 2 ms 2788 KB Output is correct
13 Correct 1 ms 2644 KB Output is correct
14 Correct 2 ms 2648 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Correct 1 ms 2648 KB Output is correct
18 Correct 2 ms 2688 KB Output is correct
19 Correct 1 ms 2648 KB Output is correct
20 Correct 2 ms 2536 KB Output is correct