답안 #741696

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
741696 2023-05-14T14:55:18 Z hfoliacots Patkice (COCI20_patkice) C++17
30 / 50
1 ms 596 KB
#include <bits/stdc++.h>

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;

vvi g;
int dest = 0, o = 0;

int rec(int n, int r) {
	if (n == dest) return r;
	for (int i: g[n]) return rec(i, r+1);
	return 1e9+1;
}

int main() {
	int r, s;
	cin >> r >> s;
	g = vvi(r*s, vi());
	for (int i = 0; i < r*s; i++) {
		char c;
		cin >> c;
		if (c == '<') g[i].push_back(i-1);
		else if (c == '>') g[i].push_back(i+1);
		else if (c == '^') g[i].push_back(i-s);
		else if (c == 'v') g[i].push_back(i+s);
		else if (c == 'o') o = i;
		else if (c == 'x') dest = i;
	}
	int m = 1e9-1;
	string d = ":(";
	if (o % s != 0) {
		int a = rec(o-1, 0);
		if (a < m) {
			m = a;
			d = ":)\nW";
		}
	}
	if (o % s != s-1) {
		int a = rec(o+1, 0);
		if (a < m) {
			m = a;
			d = ":)\nE";
		}
	}
	if (o - s >= 0) {
		int a = rec(o-s, 0);
		if (a < m) {
			m = a;
			d = ":)\nN";
		}
	}
	if (o + s < r*s) {
		int a = rec(o+s, 0);
		if (a < m) {
			m = a;
			d = ":)\nS";
		}
	}
	
	cout << d << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 596 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Incorrect 0 ms 212 KB Output isn't correct
18 Halted 0 ms 0 KB -