結果

問題 No.1045 直方体大学
ユーザー tktk_snsntktk_snsn
提出日時 2020-06-06 14:31:57
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,721 ms / 2,000 ms
コード長 1,356 bytes
コンパイル時間 322 ms
コンパイル使用メモリ 87,180 KB
実行使用メモリ 182,480 KB
最終ジャッジ日時 2023-08-25 00:53:27
合計ジャッジ時間 8,026 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 67 ms
71,252 KB
testcase_01 AC 67 ms
71,100 KB
testcase_02 AC 68 ms
71,480 KB
testcase_03 AC 70 ms
71,332 KB
testcase_04 AC 67 ms
71,100 KB
testcase_05 AC 118 ms
78,708 KB
testcase_06 AC 115 ms
78,784 KB
testcase_07 AC 114 ms
78,460 KB
testcase_08 AC 443 ms
181,992 KB
testcase_09 AC 421 ms
182,028 KB
testcase_10 AC 418 ms
182,276 KB
testcase_11 AC 414 ms
182,192 KB
testcase_12 AC 460 ms
182,480 KB
testcase_13 AC 504 ms
182,200 KB
testcase_14 AC 434 ms
182,180 KB
testcase_15 AC 492 ms
182,224 KB
testcase_16 AC 535 ms
182,196 KB
testcase_17 AC 104 ms
77,580 KB
testcase_18 AC 1,721 ms
182,204 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)

N = int(input())

# ABC[0,1,2] 底面の辺(short,long), 高さ
ABC = []
for _ in range(N):
    a, b, c = map(int, input().split())
    a, b, c = sorted([a, b, c])
    ABC.append(((a, b, c), (b, c, a), (a, c, b)))

# dp[使用した箱の集合][一番上の箱][底面がどれか] の高さの最大値
dp = [[[-1] * 3 for _ in range(N)] for _ in range(1 << N)]
for i, abc in enumerate(ABC):
    for j in range(3):
        dp[1 << i][i][j] = abc[j][2]

for bit in range(1, 1 << N):
    for i in range(N):
        if ~(bit >> i) & 1:  # 一番上の箱はi
            continue
        for j, (se1, le1, _) in enumerate(ABC[i]):
            if dp[bit][i][j] == -1:
                continue  # この積み方はぞんざいしない
            for k in range(N):  # 上に積む箱はj
                if (bit >> k) & 1:
                    continue  # 既に積んでる
                bit_next = bit | (1 << k)
                for l, (se2, le2, h) in enumerate(ABC[k]):
                    if se1 >= se2 and le1 >= le2:
                        dp[bit_next][k][l] = max(
                            dp[bit_next][k][l], dp[bit][i][j] + h)

ans = 0
for bit in range(1 << N):
    for i in range(N):
        for j in range(3):
            ans = max(ans, dp[bit][i][j])
print(ans)
0