forked from tony9402/baekjoon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
51 lines (44 loc) · 1.01 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# Authored by : gusdn3477
# Co-authored by : -
# Link : http://boj.kr/726b58947cd144afa6fa9abf2b491ac7
import sys
from collections import deque
def input():
return sys.stdin.readline().rstrip()
N = int(input())
arr = [[0 for i in range(N)] for j in range(N)]
apple = [0] * 10005
K = int(input())
for i in range(K):
a,b = map(int, input().split())
arr[a-1][b-1] = 1
L = int(input())
nx = [1,0,-1,0]
ny = [0,1,0,-1]
d = 1
time = 1
queue = deque()
queue.append((0,0))
for i in range(L):
a,b = input().split()
apple[int(a)] = b
while True:
x,y = queue.pop()
dx = nx[d] + x
dy = ny[d] + y
if (dx, dy) in queue or dx < 0 or dx >= N or dy < 0 or dy >= N:
break
if arr[dx][dy] == 1:
arr[dx][dy] = 0
queue.append((x,y))
queue.append((dx,dy))
else:
queue.append((x,y))
queue.append((dx,dy))
queue.popleft()
if apple[time] == 'L':
d = (d+1) % 4
elif apple[time] == 'D':
d = (d+3) % 4
time += 1
print(time)