Jae-Kyung Cho LLM Developers who was a Robotics engineer

Baekjoon-10422-괄호

Sorting을 계속 해줘야 하는 것을 생각하기 어려웠음!!

import sys
input = sys.stdin.readline

N = int(input())
hps = list(map(int, input().split()))
hps.sort(reverse=True)
if N < 3:
    hps += [0] * (3-N)
max_hp = hps[0]

infty = int(1e4)

dp = [[[infty] * (max_hp+1) for _ in range(max_hp+1)] for _ in range(max_hp+1)]

for scv1 in range(max_hp+1):
    for scv2 in range(scv1+1):
        for scv3 in range(scv2+1):
            # 6가지 공격 방식
            for a1,a2,a3 in [(9,3,1), (9,1,3), (3,9,1), (3,1,9), (1,3,9), (1,9,3)]:
                new1, new2, new3 = map(lambda x: max(0,x), sorted([scv1-a1, scv2-a2,scv3-a3], reverse=True))
                if new1==0 and new2==0 and new3==0:
                    dp[scv1][scv2][scv3] = 1
                else:
                    dp[scv1][scv2][scv3] = min(dp[scv1][scv2][scv3], dp[new1][new2][new3]+1)

# print(dp[12][10][4])
print(dp[hps[0]][hps[1]][hps[2]])
Comments