結果

問題 No.1045 直方体大学
ユーザー tktk_snsntktk_snsn
提出日時 2020-06-06 14:35:24
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,236 bytes
コンパイル時間 105 ms
コンパイル使用メモリ 10,900 KB
実行使用メモリ 128,356 KB
最終ジャッジ日時 2023-08-25 00:54:30
合計ジャッジ時間 13,996 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
128,356 KB
testcase_01 AC 16 ms
7,964 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 15 ms
8,268 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 TLE -
testcase_09 TLE -
testcase_10 WA -
testcase_11 WA -
testcase_12 TLE -
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
権限があれば一括ダウンロードができます

ソースコード

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 = max(max(max(d for d in dp)))
print(ans)
0