結果

問題 No.1045 直方体大学
ユーザー tpynerivertpyneriver
提出日時 2020-05-02 19:57:49
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 747 ms / 2,000 ms
コード長 873 bytes
コンパイル時間 735 ms
コンパイル使用メモリ 86,832 KB
実行使用メモリ 124,212 KB
最終ジャッジ日時 2023-08-30 03:06:54
合計ジャッジ時間 8,239 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,200 KB
testcase_01 AC 74 ms
71,380 KB
testcase_02 AC 77 ms
76,076 KB
testcase_03 AC 77 ms
76,404 KB
testcase_04 AC 79 ms
76,532 KB
testcase_05 AC 96 ms
76,524 KB
testcase_06 AC 100 ms
76,560 KB
testcase_07 AC 100 ms
76,928 KB
testcase_08 AC 529 ms
123,644 KB
testcase_09 AC 535 ms
123,728 KB
testcase_10 AC 532 ms
123,280 KB
testcase_11 AC 530 ms
123,040 KB
testcase_12 AC 553 ms
124,212 KB
testcase_13 AC 555 ms
123,368 KB
testcase_14 AC 544 ms
123,860 KB
testcase_15 AC 569 ms
123,960 KB
testcase_16 AC 571 ms
124,156 KB
testcase_17 AC 88 ms
76,512 KB
testcase_18 AC 747 ms
120,640 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from operator import itemgetter
readline = sys.stdin.readline

N = int(readline())
Box = []
LL = []
for i in range(N):
    a, b, c = map(int, readline().split())
    a, b, c = sorted([a, b, c])
    LL.extend([c, c, b])
    Box.append((i, 0, a, b, c))
    Box.append((i, 1, b, a, c))
    Box.append((i, 2, c, a, b))
LL.append(0)
Box.sort(key = lambda x: (x[3], x[4]))
INF = 10**9+7
dp = [[-INF]*(3*N+1) for _ in range(1<<N)]
dp[0][-1] = 0
for i, ori, point, _, w in Box:
    dp2 = dp[:]
    look = []
    widx = 3*i+ori
    for j in range(3*N+1):
        if j != widx and LL[j] <= w:
            look.append(j)
    for S in range(1<<N):
        if not (1<<i) & S:
            continue
        T = S^(1<<i)
        res = -INF
        for j in look:
            res = max(res, dp[T][j])
        dp[S][widx] = res + point
    
print(max(max(d) for d in dp))
        
0