얼렁뚱땅 백준 문제풀이

[백준 문제풀이] 얼렁뚱땅 2116 주사위 쌓기 풀이

MOSTAR 2022. 9. 28. 14:13

https://www.acmicpc.net/problem/2116

 

2116번: 주사위 쌓기

첫줄에는 주사위의 개수가 입력된다. 그 다음 줄부터는 한 줄에 하나씩 주사위의 종류가 1번 주사위부터 주사위 번호 순서대로 입력된다. 주사위의 종류는 각 면에 적혀진 숫자가 그림1에 있는

www.acmicpc.net

from copy import deepcopy
n = int(input())
arr = [list(map(int,input().split())) for _ in range(n)]

#return bottom, top
# i == bottom
def bottom_top(i) :
    if i == 0 :
        return 0, 5
    elif i == 1 :
        return 1, 3
    elif i == 2 :
        return 2, 4
    elif i == 3 :
        return 3, 1
    elif i == 4 :
        return 4, 2
    else :
        return 5, 0

answer = -1
for i in range(6) :
    temp_sum = 0
    bottom_idx, top_idx = bottom_top(i)
    bottom, top = arr[0][bottom_idx], arr[0][top_idx]
    copy_list = deepcopy(arr[0])
    copy_list[bottom_idx] = 0
    copy_list[top_idx] = 0
    temp_sum += max(copy_list)

    for j in range(1,n) :
        bottom_idx = arr[j].index(top)
        bottom_idx, top_idx = bottom_top(bottom_idx)
        bottom, top = arr[j][bottom_idx], arr[j][top_idx]
        copy_list = deepcopy(arr[j])
        copy_list[bottom_idx] = 0
        copy_list[top_idx] = 0
        temp_sum += max(copy_list)

    answer = max(answer,temp_sum)

print(answer)