-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path14891.py
More file actions
77 lines (49 loc) · 1.16 KB
/
Copy path14891.py
File metadata and controls
77 lines (49 loc) · 1.16 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import sys
top = []
for i in range(4):
top.append(list(sys.stdin.readline().rstrip()))
N = int(sys.stdin.readline())
T = []
for i in range(N):
T.append(list(map(int,sys.stdin.readline().split())))
def move_clock(gear):
temp = gear.pop()
gear.insert(0,temp)
def move_clockwise(gear):
temp = gear.pop(0)
gear.append(temp)
for i in range(N):
top_n = T[i][0]-1
connect = [0,0,0]
direction = [0,0,0,0]
for j in range(3):
if top[j][2] != top[j+1][6]:
connect[j] = 1
direction[top_n] = T[i][1]
if top_n -1 >= 0:
for j in range(top_n-1,-1,-1):
if connect[j] == 0:
break
elif connect[j] == 1:
direction[j] = direction[j+1] * -1
if top_n + 1 < 4:
for j in range(top_n+1,4):
if connect[j-1] == 0:
break
elif connect[j-1] == 1:
direction[j] = direction[j-1] * -1
for i in range(4):
if direction[i] == 1:
move_clock(top[i])
elif direction[i] == -1:
move_clockwise(top[i])
answer = 0
if top[0][0] == '1':
answer += 1
if top[1][0] == '1':
answer += 2
if top[2][0] == '1':
answer += 4
if top[3][0] == '1':
answer += 8
print(answer)