Submission #486320

# Submission time Handle Problem Language Result Execution time Memory
486320 2021-11-11T08:44:37 Z Christopher_ Patkice (COCI20_patkice) C++17
30 / 50
1 ms 332 KB
#include <bits/stdc++.h>

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
	int n, m;
	cin >> n >> m;
	vector<string> g(n);
	pair<int, int> st, fi;
	vector<vector<bool>> vis(n, vector<bool>(m));
	for (int i = 0; i < n; ++i) {
		cin >> g[i];
		for (int j = 0; j < m; ++j) {
			if (g[i][j] == 'o') {
				st = {i, j};
			} else if (g[i][j] == 'x') {
				fi = {i, j};
			}
		}
	}
	struct node {
		int d, x, y, ty;

		bool operator <(const node& o) const {
			return d > o.d; 
		}
	};
	auto e = [&](int x, int y) {
		if (x >= 0 && x < n && y >= 0 && y < m && !vis[x][y] && g[x][y] != '.') return true;
		return false;
	};
	auto pr = [](int k) {
		if (k == 0) {
			return 'E';
		} else if (k == 1) {
			return 'S';
		} else if (k == 2) {
			return 'W';
		} else {
			return 'N';
		}
	};
	queue<node> q;
	q.push({0, st.first, st.second, -1});
	while (!q.empty()) {
		int d = q.front().d, x = q.front().x, y = q.front().y, ty = q.front().ty; q.pop();
		if (vis[x][y]) {
			continue;
		}
		vis[x][y] = true;
		if (x == fi.first && y == fi.second) {
			cout << ":)" << '\n' << pr(ty) << '\n';
			return 0;
		} else if (x == st.first && y == st.second) {
			for (int k = 0; k < 4; ++k) {
				int nx = x + dx[k], ny = y + dy[k];
				if (e(nx, ny)) {
					if (x == st.first && y == st.second) {
						q.push({d + 1, nx, ny, k});
					} else {
						q.push({d + 1, nx, ny, ty});
					}
				}
			}
		} else {
			if (g[x][y] == '^') {
				q.push({d + 1, x - 1, y, ty});
			} else if (g[x][y] == 'v') {
				q.push({d + 1, x + 1, y, ty});
			} else if (g[x][y] == '>') {
				q.push({d + 1, x, y + 1, ty});
			} else if (g[x][y] == '<') {
				q.push({d + 1, x, y - 1, ty});
			}
		}
	}
	cout << ":(" << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 308 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 308 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 332 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 308 KB Output is correct
15 Correct 0 ms 312 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Incorrect 0 ms 204 KB Output isn't correct
19 Halted 0 ms 0 KB -