흙금이네 블로그

[BOJ] 20061 - 모노미노도미노 2 (Python) 본문

알고리즘

[BOJ] 20061 - 모노미노도미노 2 (Python)

흙금 2023. 3. 28. 11:22

 

 

아이디어

 

조건에 따라 블록을 처리하는 보드를 구현하되, 블록을 쉽게 처리하기 위해 파란색 보드는 전치하여 구현한다.

 

 

풀이

 

import sys

input = sys.stdin.readline

def solution():
    N = int(input())
    green = [[0]*4 for _ in range(6)]
    blue = [[0]*4 for _ in range(6)]
    score = cnt = 0
    for _ in range(N):
        t, x, y = map(int, input().split())
        if t == 1:
            cnt += 2
            for r in range(2, 6):
                if green[r][y]:
                    green[r-1][y] = 1
                    break
            else:
                green[5][y] = 1
            for c in range(2, 6):
                if blue[c][x]:
                    blue[c-1][x] = 1
                    break
            else:
                blue[5][x] = 1
        else:
            cnt += 4
            if t == 3:
                green, blue = blue, green
                x, y = y, x
            for r in range(2, 6):
                if green[r][y] or green[r][y+1]:
                    green[r-1][y] = green[r-1][y+1] = 1
                    break
            else:
                green[5][y] = green[5][y+1] = 1
            for c in range(2, 6):
                if blue[c][x]:
                    blue[c-1][x] = blue[c-2][x] = 1
                    break
            else:
                blue[5][x] = blue[4][x] = 1
            if t == 3:
                green, blue = blue, green
        for i in range(2, 6):
            if sum(green[i]) == 4:
                score += 1
                cnt -= 4
                del green[i]
                green = [[0]*4]+green
            if sum(blue[i]) == 4:
                score += 1
                cnt -= 4
                del blue[i]
                blue = [[0]*4]+blue
        while sum(green[1]) != 0:
            cnt -= sum(green.pop())
            green = [[0]*4]+green
        while sum(blue[1]) != 0:
            cnt -= sum(blue.pop())
            blue = [[0]*4]+blue
    print(score)
    print(cnt)

solution()

 

Comments