답안 #448123

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
448123 2021-07-29T02:49:16 Z flappybird Patkice (COCI20_patkice) C++14
30 / 50
1 ms 460 KB
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,fma")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
#define MAX 101010
#define MOD 1000000007
#define ln '\n'
ll mp[101][101];
ll vis[101][101];
pll dir[4];
ll R, S;
bool c(ll x, ll y) {
	return (1 <= x && x <= R) && (1 <= y && y <= S);
}
void init() {
	ll i, j;
	for (i = 1; i <= R; i++) {
		for (j = 1; j <= S; j++) vis[i][j] = 0;
	}
}
bool chk(ll x, ll y) {
	if (vis[x][y]) return 0;
	vis[x][y] = 1;
	if (!c(x, y)) return 0;
	if (mp[x][y] == -1) return 0;
	if (mp[x][y] >= 4) return 1;
	return chk(x + dir[mp[x][y]].first, y + dir[mp[x][y]].second);
}
signed main() {
	cin >> R >> S;
	ll i, j;
	dir[0] = { -1, 0 };
	dir[1] = { 0, 1 };
	dir[2] = { 1, 0 };
	dir[3] = { 0, -1 };
	vector<string> input;
	for (i = 1; i <= R; i++) {
		string s;
		cin >> s;
		input.push_back(s);
	}
	map<char, ll> asdf;
	asdf['.'] = -1;
	asdf['^'] = 0;
	asdf['>'] = 1;
	asdf['v'] = 2;
	asdf['<'] = 3;
	asdf['o'] = 4;
	asdf['x'] = 5;
	pll st, en;
	for (i = 1; i <= R; i++) {
		for (j = 1; j <= S; j++) {
			mp[i][j] = asdf[input[i - 1][j - 1]];
			if (mp[i][j] == 4) st = { i, j };
		}
	}
	ll ans = -1;
	init();
	mp[st.first][st.second] = 0;
	if (chk(st.first, st.second)) ans = 0;
	init();
	mp[st.first][st.second] = 1;
	if (chk(st.first, st.second)) ans = 1;
	init();
	mp[st.first][st.second] = 2;
	if (chk(st.first, st.second)) ans = 2;
	init();
	mp[st.first][st.second] = 3;
	if (chk(st.first, st.second)) ans = 3;
	if (ans == -1) {
		cout << ":(" << ln;
		return 0;
	}
	cout << ":)" << ln;
	if (ans == 0) cout << 'N' << ln;
	if (ans == 1) cout << 'E' << ln;
	if (ans == 2) cout << 'S' << ln;
	if (ans == 3) cout << 'W' << ln;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -