https://www.acmicpc.net/problem/3190
내 풀이
import sys
from collections import deque
# input = sys.stdin.readline
N = int(input()) # 맵크기 n*n
K = int(input())
apple = [tuple(map(int, input().split())) for _ in range(K)]
L = int(input())
moves = {}
for i in range(L):
X, C = input().split()
moves[int(X)] = C
dir_ = [(0, 1), (1, 0), (0, -1), (-1, 0)] ## 우, 하, 좌, 상
MAP = [[0] * N for _ in range(N)]
for r, c in apple:
MAP[r-1][c-1] = 'a'
def sol():
global MAP
d = 0
time = 0
body = deque([(0, 0)])
nx, ny = 0, 0
while True:
nx = nx + dir_[d][0]
ny = ny + dir_[d][1]
time += 1
if nx < 0 or ny < 0 or nx >= N or ny >= N or (nx, ny) in body:
return time
if MAP[nx][ny] == 'a':
MAP[nx][ny] = 0
else:
body.popleft()
body.append((nx, ny))
if time in moves.keys():
if moves[time] == 'L':
d = (d - 1)
else:
d = (d + 1)
if d >= 4:
d -= 4
if d < 0 :
d += 4
print(sol())
Feedback
- 없뜸 ! 10분 컷
'코딩 문제 > 백준' 카테고리의 다른 글
[백준_14499번] 주사위 굴리기 (0) | 2022.02.21 |
---|---|
[백준_13458번] 시험 감독(python) (0) | 2022.02.19 |
[백준_3191번] 백조의 호수 (python) (0) | 2022.02.17 |
[백준_1665번] 가운데를 말해요 (python) (0) | 2022.02.15 |
[백준_12865번] 평범한 배낭 (python) (0) | 2022.02.15 |