백준 1343번: 폴리오미노 #Python

ColorlessDia·2024년 11월 15일

algorithm/baekjoon

목록 보기
362/814
board = input()

is_possible = True

completed_board = ''

x_count = 0

for i, char in enumerate(board, 1):

    if char == 'X':
        x_count += 1

    if (
        (0 < x_count and char == '.') or
        (0 < x_count and i == len(board))
      ):
        
        if x_count % 2 != 0:
            is_possible = False
            break
        
        a_count = x_count // 4
        b_count = x_count % 4 // 2

        completed_board += ('AAAA' * a_count) + ('BB' * b_count)

        x_count = 0
    
    if char == '.':
        completed_board += '.'

if is_possible:
    print(completed_board)
else:
    print(-1)

0개의 댓글