https://www.acmicpc.net/problem/20061
def get_block(t, y, x, isBlue):
if isBlue:
if t == 1:
return [[0, y]]
if t == 2:
return [[0, y], [1, y]]
if t == 3:
return [[0, y], [0, y+1]]
else:
if t == 1:
return [[0, x]]
if t == 2:
return [[0, x], [0, x+1]]
if t == 3:
return [[0, x], [1, x]]
def set_block(board, block):
curr = []
for i in range(len(block)-1, -1, -1):
curr.append(block[i])
while True:
can_down = True
for y, x in curr:
if not (y <= 4 and board[y+1][x] == 0):
can_down = False
if can_down:
for i in range(len(curr)):
curr[i][0] += 1
else:
break
for y, x in curr:
board[y][x] = 1
def down_filled(board):
filled = [0] * 6
for i in range(6):
if sum(board[i]) == 4:
filled[i] = 1
y1, y2 = 5, 5
while y1 >= 0 and y2 >= 0:
if filled[y1]:
y1 -= 1
else:
board[y2] = board[y1][:]
y1 -= 1
y2 -= 1
return sum(filled)
def down_out(board):
out = 0
for i in range(2):
if sum(board[i]) > 0:
out += 1
y1, y2 = 5 - out, 5
while y1 >= 0 and y2 >= 0:
board[y2] = board[y1][:]
y1 -= 1
y2 -= 1
board[0] = [0,0,0,0]
board[1] = [0,0,0,0]
# init
import sys
read = sys.stdin.readline
n = int(read())
info = [list(map(int, read().split())) for _ in range(n)]
board = [
[[0]*4 for _ in range(6)],
[[0]*4 for _ in range(6)],
]
# start
score = 0
for t, y, x in info:
for i in range(2):
block = get_block(t, y, x, i)
set_block(board[i], block)
score += down_filled(board[i])
down_out(board[i])
count = 0
for i in range(2):
for j in range(6):
for k in range(4):
if board[i][j][k]:
count += 1
print(score)
print(count)