-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path4-4.py
50 lines (38 loc) · 740 Bytes
/
4-4.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
n,m = map(int,input().split())
x,y,b = map(int,input().split())
d = [[0]*m for _ in range(n)]
data = []
for i in range(n):
data.append(list(map(int, input().split())))
d[x][y] = 1
dx = [-1,0,1,0]
dy = [0,1,0,-1]
turn = 0
count = 1
def turn_left():
global b
b-=1
if b == -1:
b = 3
while 1:
turn_left()
nx = x + dx[b]
ny = y + dy[b]
if d[nx][ny]==0 and data[nx][ny] == 0:
d[nx][ny]= 1
x = nx
y = ny
count +=1
turn = 0
else:
turn +=1
if turn == 4:
nx = x-dx[b]
ny = y-dy[b]
if d[nx][ny] == 0:
x=nx
y = ny
else:
break
turn = 0
print(count)