Submission #741682

# Submission time Handle Problem Language Result Execution time Memory
741682 2023-05-14T14:25:39 Z Alma Patkice (COCI20_patkice) C++17
50 / 50
1 ms 552 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL);

	int r, c;
	cin >> r >> c;
	vector<vector<char>> m(r, vector<char>(c));

	string s;
	int x0 = 0, y0 = 0;
	for (int i = 0; i < r; i++) {
		cin >> s;
		for (int j = 0; j < c; j++) {
			m[i][j] = s[j];
			if (s[j] == 'o') {
				x0 = i;
				y0 = j;
			}
		}
	}

	map<char, pair<int, int>> dir;
	dir['>'] = {0, 1};
	dir['<'] = {0, -1};
	dir['v'] = {1, 0};
	dir['^'] = {-1, 0};

	// Order: E, N, S, W
	vector<pair<int, int>> st;
	st.push_back({0, 1});
	st.push_back({-1, 0});
	st.push_back({1, 0});
	st.push_back({0, -1});

	int x, y, cnt, idx = -1, mn = 1e9;

	for (int i = 0; i < 4; i++) {
		x = x0 + st[i].first;
		y = y0 + st[i].second;
		cnt = 0;

		while (true) {
			if (m[x][y] == '.' || m[x][y] == 'o') {
				break;
			} else if (m[x][y] == 'x') {
				if (cnt < mn) {
					mn = cnt;
					idx = i;
				}
				break;
			}
			char d = m[x][y];
			x += dir[d].first;
			y += dir[d].second;
			cnt++;
		}
	}

	vector<char> let = {'E', 'N', 'S', 'W'};

	if (idx != -1) {
		cout << ":)\n";
		cout << let[idx] << '\n';
	} else {
		cout << ":(\n";
	}

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 316 KB Output is correct
8 Correct 1 ms 324 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 552 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 316 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 320 KB Output is correct
18 Correct 0 ms 320 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct