1
+ import sys
2
+ input = sys .stdin .readline
3
+
4
+ arr = [[0 ]* 10 for _ in range (10 )]
5
+
6
+ N = int (input ())
7
+ point = 0
8
+ # move1 -> check -> done? yes-> move2 -> check -> done? -> move2 ....
9
+ # no-> check2 -> done? -> move2 -
10
+ #red to blue and green
11
+ def move1 (x ,y ,mode ):
12
+ if mode == 1 :
13
+ nx ,ny = x ,4
14
+ while ny < 10 and not arr [nx ][ny ]:
15
+ ny += 1
16
+ arr [nx ][ny - 1 ]= arr [x ][y ]
17
+ nx ,ny = 4 ,y
18
+ while nx < 10 and not arr [nx ][ny ]:
19
+ nx += 1
20
+ arr [nx - 1 ][ny ]= arr [x ][y ]
21
+ arr [x ][y ]= 0
22
+ #가로
23
+ elif mode == 2 :
24
+ nx ,ny = x ,4
25
+ while ny < 10 and not arr [nx ][ny ]:
26
+ ny += 1
27
+ arr [nx ][ny - 2 ]= arr [nx ][ny - 1 ]= arr [x ][y ]
28
+ nx ,ny = 4 ,y
29
+ while nx < 10 and arr [nx ][ny ]== 0 and arr [nx ][ny + 1 ]== 0 :
30
+ nx += 1
31
+ arr [nx - 1 ][ny ]= arr [nx - 1 ][ny + 1 ]= arr [x ][y ]
32
+ arr [x ][y ],arr [x ][y + 1 ]= 0 ,0
33
+ else :
34
+ nx ,ny = x ,4
35
+ while ny < 10 and arr [nx ][ny ]== 0 and arr [nx + 1 ][ny ]== 0 :
36
+ ny += 1
37
+ arr [nx ][ny - 1 ]= arr [nx + 1 ][ny - 1 ]= arr [x ][y ]
38
+ nx ,ny = 4 ,y
39
+ while nx < 10 and not arr [nx ][ny ]:
40
+ nx += 1
41
+ arr [nx - 2 ][ny ]= arr [nx - 1 ][ny ]= arr [x ][y ]
42
+ arr [x ][y ],arr [x + 1 ][y ]= 0 ,0
43
+ # check special zone
44
+ def check2 ():
45
+ ch = [0 ,0 ]
46
+ for x in range (4 ,6 ):
47
+ for y in range (4 ):
48
+ if arr [x ][y ]:
49
+ ch [x % 2 ]= 1
50
+ break
51
+ ch = sum (ch )
52
+ if ch :
53
+ for x in range (9 ,3 ,- 1 ):
54
+ for y in range (4 ):
55
+ arr [x ][y ] = arr [x - ch ][y ]
56
+ ch = [0 ,0 ]
57
+ for y in range (4 ,6 ):
58
+ for x in range (4 ):
59
+ if arr [x ][y ]:
60
+ ch [y % 2 ]= 1
61
+ break
62
+ ch = sum (ch )
63
+ if ch :
64
+ for y in range (9 ,3 ,- 1 ):
65
+ for x in range (4 ):
66
+ arr [x ][y ] = arr [x ][y - ch ]
67
+
68
+ # check point
69
+ def check ():
70
+ global point
71
+ check_done = False
72
+ x = 6
73
+ while x < 10 :
74
+ if arr [x ][0 ] and arr [x ][1 ] and arr [x ][2 ] and arr [x ][3 ]:
75
+ for i in range (4 ):
76
+ arr [x ][i ] = 0
77
+ point += 1
78
+ check_done = True
79
+ x += 1
80
+ y = 6
81
+ while y < 10 :
82
+ if arr [0 ][y ] and arr [1 ][y ] and arr [2 ][y ] and arr [3 ][y ]:
83
+ for i in range (4 ):
84
+ arr [i ][y ] = 0
85
+ check_done = True
86
+ point += 1
87
+ y += 1
88
+ return check_done
89
+
90
+ def move2 ():
91
+ for y in range (8 ,3 ,- 1 ):
92
+ for x in range (4 ):
93
+ if arr [x ][y ]:
94
+ if x < 3 and arr [x ][y ]== arr [x + 1 ][y ]:
95
+ ny = y + 1
96
+ while ny < 10 and arr [x ][ny ]== 0 and arr [x + 1 ][ny ]== 0 :
97
+ ny += 1
98
+ if ny - 1 != y :
99
+ arr [x ][ny - 1 ]= arr [x + 1 ][ny - 1 ]= arr [x ][y ]
100
+ arr [x ][y ]= arr [x + 1 ][y ]= 0
101
+ elif x > 0 and arr [x ][y ]== arr [x - 1 ][y ]:
102
+ ny = y + 1
103
+ while ny < 10 and arr [x ][ny ]== 0 and arr [x - 1 ][ny ]== 0 :
104
+ ny += 1
105
+ if ny - 1 != y :
106
+ arr [x ][ny - 1 ]= arr [x - 1 ][ny - 1 ]= arr [x ][y ]
107
+ arr [x ][y ]= arr [x - 1 ][y ]= 0
108
+ else :
109
+ ny = y + 1
110
+ while ny < 10 and arr [x ][ny ]== 0 :
111
+ ny += 1
112
+ if ny - 1 != y :
113
+ arr [x ][ny - 1 ]= arr [x ][y ]
114
+ arr [x ][y ]= 0
115
+
116
+ for x in range (8 ,3 ,- 1 ):
117
+ for y in range (4 ):
118
+ if arr [x ][y ]:
119
+ if y < 3 and arr [x ][y ]== arr [x ][y + 1 ]:
120
+ nx = x + 1
121
+ while nx < 10 and arr [nx ][y ]== 0 and arr [nx ][y + 1 ]== 0 :
122
+ nx += 1
123
+ if nx - 1 != x :
124
+ arr [nx - 1 ][y ]= arr [nx - 1 ][y + 1 ]= arr [x ][y ]
125
+ arr [x ][y ]= arr [x ][y + 1 ]= 0
126
+ elif y > 0 and arr [x ][y ]== arr [x ][y - 1 ]:
127
+ nx = x + 1
128
+ while nx < 10 and arr [nx ][y ]== 0 and arr [nx ][y - 1 ]== 0 :
129
+ nx += 1
130
+ if nx - 1 != x :
131
+ arr [nx - 1 ][y ]= arr [nx ][y - 1 ]= arr [x ][y ]
132
+ arr [x ][y ]= arr [x ][y - 1 ]= 0
133
+ else :
134
+ nx = x + 1
135
+ while nx < 10 and arr [nx ][y ]== 0 :
136
+ nx += 1
137
+ if nx - 1 != x :
138
+ arr [nx - 1 ][y ]= arr [x ][y ]
139
+ arr [x ][y ]= 0
140
+
141
+
142
+ def checkLast ():
143
+ ans = 0
144
+ for x in range (4 ):
145
+ for y in range (6 ,10 ):
146
+ if arr [x ][y ]:ans += 1
147
+ if arr [y ][x ]:ans += 1
148
+ return ans
149
+ def printBoard ():
150
+ for y in range (10 ):
151
+ print (' ' .join (map (str ,arr [y ])))
152
+ print ()
153
+ for i in range (1 ,N + 1 ):
154
+ t ,x ,y = map (int ,input ().split ())
155
+ if t == 1 :
156
+ arr [x ][y ]= i
157
+ elif t == 2 :
158
+ arr [x ][y ]= i
159
+ arr [x ][y + 1 ]= i
160
+ else :
161
+ arr [x + 1 ][y ]= i
162
+ arr [x ][y ]= i
163
+ #printBoard()
164
+ move1 (x ,y ,t )
165
+ #printBoard()
166
+ while check ():
167
+ #printBoard()
168
+ move2 ()
169
+ #printBoard()
170
+ check2 ()
171
+ #printBoard()
172
+ print (point )
173
+ print (checkLast ())
0 commit comments