답안 #377622

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
377622 2021-03-14T13:13:42 Z dimashii Patkice (COCI20_patkice) C++17
50 / 50
1 ms 1516 KB
#include <bits/stdc++.h>

#define ll long long

using namespace std;

const int mxN = 5e3 + 5, mod = 1e9 + 7;

char a[mxN][mxN], d[mxN][mxN];

bool used[mxN][mxN];

int r, s;

int main() {
	ios :: sync_with_stdio(false), cin.tie(nullptr);
	cin >> r >> s;
	for (int i = 1; i <= r; ++i) {
		for (int j = 1; j <= s; ++j) { 
			cin >> a[i][j]; 
			d[i][j] = '#';
		}
	}	
	queue <pair <int, int> > q;
	for (int i = 1; i <= r; ++i) {
		for (int j = 1; j <= s; ++j) {
			if (a[i][j] == 'o') {
				used[i][j] = 1;
				q.push({i, j});
				break;
			}
		}
	}
	while (!q.empty()) {
		int i = q.front().first;
		int j = q.front().second;
		q.pop();
		if (a[i][j] == 'x') {
			cout << ":)\n" << d[i][j];
			return 0;
		}
		if (a[i][j] == 'o') {
			if (j + 1 <= s) {
				used[i][j + 1] = 1;
				q.push({i, j + 1});
				d[i][j + 1] = 'E';
			}
			if (i - 1 > 0) {
				used[i - 1][j] = 1;
				q.push({i - 1, j});
				d[i - 1][j] = 'N';
			}
			if (i + 1 <= r) {
				used[i + 1][j] = 1;
				q.push({i + 1, j});
				d[i + 1][j] = 'S';
			}
			if (j - 1 > 0) {
				used[i][j - 1] = 1;
				q.push({i, j - 1});
				d[i][j - 1] = 'W';
			}
		}
		else if (a[i][j] != '.') {
			if (a[i][j] == 'v' && !used[i + 1][j]) {
				used[i + 1][j] = 1;
				q.push({i + 1, j});
				d[i + 1][j] = d[i][j]; 
			}
			if (a[i][j] == '^' && !used[i - 1][j]) {
				used[i - 1][j] = 1;
				q.push({i - 1, j});
				d[i - 1][j] = d[i][j];
			}
			if (a[i][j] == '>' && !used[i][j + 1]) {
				used[i][j + 1] = 1;
				q.push({i, j + 1});
				d[i][j + 1] = d[i][j];
			}
			if (a[i][j] == '<' && !used[i][j - 1]) {
				used[i][j - 1] = 1;
				q.push({i, j - 1});
				d[i][j - 1] = d[i][j]; 
			}
		}
	}
	cout << ":(";
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 768 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 1260 KB Output is correct
4 Correct 1 ms 1260 KB Output is correct
5 Correct 1 ms 876 KB Output is correct
6 Correct 1 ms 620 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Correct 1 ms 1004 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 1004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 620 KB Output is correct
2 Correct 1 ms 1004 KB Output is correct
3 Correct 1 ms 620 KB Output is correct
4 Correct 1 ms 1004 KB Output is correct
5 Correct 1 ms 1260 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 1 ms 876 KB Output is correct
8 Correct 1 ms 1132 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 1516 KB Output is correct
11 Correct 1 ms 1132 KB Output is correct
12 Correct 1 ms 1152 KB Output is correct
13 Correct 1 ms 1132 KB Output is correct
14 Correct 1 ms 1004 KB Output is correct
15 Correct 1 ms 1004 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct