Submission #934106

# Submission time Handle Problem Language Result Execution time Memory
934106 2024-02-26T19:24:28 Z pakapu Patkice (COCI20_patkice) C++17
30 / 50
1 ms 616 KB
#include <bits/stdc++.h>

using namespace std;

int can_get_home(int i, int j, int curr_moves, vector<string> &land)
{
	if (i >= land.size()
		|| j >= land[0].size()
		|| i < 0
		|| j < 0) {
		return 1e9 + 1;
	}

	switch (land[i][j]) {
	case '>':
		return can_get_home(i, j + 1, curr_moves + 1, land);
		break;
	case '<':
		return can_get_home(i, j - 1, curr_moves + 1, land);
		break;
	case '^':
		return can_get_home(i - 1, j, curr_moves + 1, land);
		break;
	case 'v':
		return can_get_home(i + 1, j, curr_moves + 1, land);
		break;
	case 'x':
		return curr_moves;
	default:
		return 1e9 + 1;
	}
}

int main()
{
	int n, m;
	cin >> n >> m;

	vector<string> land(n);
	int start_i = -1;
	int start_j = -1;

	for (int i = 0; i < n; i++) {
		cin >> land[i];
		for (int j = 0; j < land[i].size(); j++) {
			if (land[i][j] == 'o') {
				start_i = i;
				start_j = j;
			}
		}
	}

	assert(start_i != -1);
	assert(start_j != -1);

	int min_moves = 1e9 + 1;
	int curr_moves = -1;
	char min_dir = '!';

	curr_moves = can_get_home(start_i - 1, start_j, 0, land);
	if (curr_moves < min_moves) {
		min_moves = curr_moves;
		min_dir = 'N';
	}
	curr_moves = can_get_home(start_i, start_j + 1, 0, land);
	if (curr_moves < min_moves) {
		min_moves = curr_moves;
		min_dir = 'E';
	}
	curr_moves = can_get_home(start_i, start_j - 1, 0, land);
	if (curr_moves < min_moves) {
		min_moves = curr_moves;
		min_dir = 'W';
	}
	curr_moves = can_get_home(start_i + 1, start_j, 0, land);
	if (curr_moves < min_moves) {
		min_moves = curr_moves;
		min_dir = 'S';
	}

	if (min_moves == 1e9 + 1) {
		cout << ":(\n";
	}
	else {
		cout << ":)\n";
		cout << min_dir << '\n';
	}

	return 0;
}

Compilation message

patkice.cpp: In function 'int can_get_home(int, int, int, std::vector<std::__cxx11::basic_string<char> >&)':
patkice.cpp:7:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::__cxx11::basic_string<char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    7 |  if (i >= land.size()
      |      ~~^~~~~~~~~~~~~~
patkice.cpp:8:8: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 |   || j >= land[0].size()
      |      ~~^~~~~~~~~~~~~~~~~
patkice.cpp: In function 'int main()':
patkice.cpp:45:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |   for (int j = 0; j < land[i].size(); j++) {
      |                   ~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 432 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Incorrect 0 ms 356 KB Output isn't correct
17 Halted 0 ms 0 KB -