답안 #486308

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
486308 2021-11-11T08:22:12 Z Christopher_ Patkice (COCI20_patkice) C++17
0 / 50
1 ms 204 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};
			}
		}
	}
	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;
	};
	int x, y;
	x = st.first, y = st.second;
	x++;
	while (x != fi.first || y != fi.second) {
		if (!e(x, y)) {
			break;
		}
		vis[x][y] = true;
		if (g[x][y] == '^') {
			x--;
		} else if (g[x][y] == 'v') {
			x++;
		} else if (g[x][y] == '>') {
			y++;
		} else {
			--y;
		}
	}
	if (x == fi.first && y == fi.second) {
		return cout << ":)" << '\n' << "S" << '\n', 0;
	}
	x = st.first, y = st.second;
	x--;
	while (x != fi.first || y != fi.second) {
		if (!e(x, y)) {
			break;
		}
		vis[x][y] = true;
		if (g[x][y] == '^') {
			x--;
		} else if (g[x][y] == 'v') {
			x++;
		} else if (g[x][y] == '>') {
			y++;
		} else {
			--y;
		}
	}
	if (x == fi.first && y == fi.second) {
		return cout << ":)" << '\n' << "N" << '\n', 0;
	}
	x = st.first, y = st.second;
	y++;
	while (x != fi.first || y != fi.second) {
		if (!e(x, y)) {
			break;
		}
		vis[x][y] = true;
		if (g[x][y] == '^') {
			x--;
		} else if (g[x][y] == 'v') {
			x++;
		} else if (g[x][y] == '>') {
			y++;
		} else {
			--y;
		}
	}
	if (x == fi.first && y == fi.second) {
		return cout << ":)" << '\n' << "R" << '\n', 0;
	}
	x = st.first, y = st.second;
	y--;
	while (x != fi.first || y != fi.second) {
		if (!e(x, y)) {
			break;
		}
		vis[x][y] = true;
		if (g[x][y] == '^') {
			x--;
		} else if (g[x][y] == 'v') {
			x++;
		} else if (g[x][y] == '>') {
			y++;
		} else {
			--y;
		}
	}
	if (x == fi.first && y == fi.second) {
		return cout << ":)" << '\n' << "L" << '\n', 0;
	}
	cout << ":(" << '\n';
}

Compilation message

patkice.cpp: In function 'int main()':
patkice.cpp:8:12: warning: unused variable 'dx' [-Wunused-variable]
    8 |  const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
      |            ^~
patkice.cpp:8:35: warning: unused variable 'dy' [-Wunused-variable]
    8 |  const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
      |                                   ^~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -