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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
from collections import deque
gear1 = input()
gear1 = deque(gear1)
gear2 = input()
gear2 = deque(gear2)
gear3 = input()
gear3 = deque(gear3)
gear4 = input()
gear4 = deque(gear4)
m = []
k = int(input())
sum = 0
for i in range(k):
m.append(list(map(int, input().split())))
def c(gear):
gear.appendleft(gear[7])
gear.pop()
def rc(gear):
gear.append(gear[0])
gear.popleft()
for i in range(k):
if m[i][0]==1:
if gear1[2]!=gear2[6]:
if m[i][1]==1:
c(gear1)
if gear2[2]!=gear3[6]:
if gear3[2]!=gear4[6]:
rc(gear4)
c(gear3)
rc(gear2)
if m[i][1]==-1:
rc(gear1)
if gear2[2]!=gear3[6]:
if gear3[2]!=gear4[6]:
c(gear4)
rc(gear3)
c(gear2)
elif gear1[2]==gear2[6]:
if m[i][1]==1:
c(gear1)
if m[i][1]==-1:
rc(gear1)
if m[i][0]==2:
if gear2[2]!=gear3[6]:
if m[i][1]==1:
if gear3[2]!=gear4[6]:
c(gear4)
if gear1[2]!=gear2[6]:
rc(gear1)
c(gear2)
rc(gear3)
if m[i][1]==-1:
if gear3[2]!=gear4[6]:
rc(gear4)
if gear1[2]!=gear2[6]:
c(gear1)
rc(gear2)
c(gear3)
elif gear2[2]==gear3[6]:
if m[i][1]==1:
if gear1[2]!=gear2[6]:
rc(gear1)
c(gear2)
if m[i][1]==-1:
if gear1[2]!=gear2[6]:
c(gear1)
rc(gear2)
if m[i][0]==3:
if gear2[2]!=gear3[6]:
if m[i][1]==1:
if gear1[2]!=gear2[6]:
c(gear1)
if gear3[2]!=gear4[6]:
rc(gear4)
c(gear3)
rc(gear2)
if m[i][1]==-1:
if gear1[2]!=gear2[6]:
rc(gear1)
if gear3[2]!=gear4[6]:
c(gear4)
rc(gear3)
c(gear2)
elif gear2[2]==gear3[6]:
if m[i][1]==1:
if gear3[2]!=gear4[6]:
rc(gear4)
c(gear3)
if m[i][1]==-1:
if gear3[2]!=gear4[6]:
c(gear4)
rc(gear3)
if m[i][0]==4:
if gear3[2]!=gear4[6]:
if m[i][1]==1:
c(gear4)
if gear2[2]!=gear3[6]:
if gear1[2]!=gear2[6]:
rc(gear1)
c(gear2)
rc(gear3)
if m[i][1]==-1:
rc(gear4)
if gear2[2]!=gear3[6]:
if gear1[2]!=gear2[6]:
c(gear1)
rc(gear2)
c(gear3)
elif gear3[2]==gear4[6]:
if m[i][1]==1:
c(gear4)
if m[i][1]==-1:
rc(gear4)
if gear1[0]=='1':
sum+=1
if gear2[0]=='1':
sum+=2
if gear3[0]=='1':
sum+=4
if gear4[0]=='1':
sum+=8
print(sum)
|
cs |
'백준' 카테고리의 다른 글
백준 4673번: 셀프 넘버 (0) | 2021.07.02 |
---|---|
백준 2960번: 에라토스테네스의 체 (0) | 2021.07.02 |
백준 14500번: 테트로미노 (0) | 2021.07.02 |
백준 4949번: 균형잡힌 세상 (0) | 2021.06.29 |
백준 11866번: 요세푸스 문제 0 (0) | 2021.06.27 |