結果

問題 No.1045 直方体大学
ユーザー tamatotamato
提出日時 2020-05-02 00:25:32
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 684 ms / 2,000 ms
コード長 1,094 bytes
コンパイル時間 301 ms
コンパイル使用メモリ 87,224 KB
実行使用メモリ 99,748 KB
最終ジャッジ日時 2023-08-26 17:59:02
合計ジャッジ時間 6,848 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 61 ms
71,672 KB
testcase_01 AC 61 ms
71,736 KB
testcase_02 AC 66 ms
75,604 KB
testcase_03 AC 63 ms
75,588 KB
testcase_04 AC 65 ms
75,616 KB
testcase_05 AC 79 ms
76,732 KB
testcase_06 AC 78 ms
76,672 KB
testcase_07 AC 82 ms
76,804 KB
testcase_08 AC 679 ms
99,660 KB
testcase_09 AC 375 ms
99,748 KB
testcase_10 AC 684 ms
99,716 KB
testcase_11 AC 667 ms
99,476 KB
testcase_12 AC 408 ms
91,032 KB
testcase_13 AC 406 ms
91,176 KB
testcase_14 AC 320 ms
89,764 KB
testcase_15 AC 265 ms
91,940 KB
testcase_16 AC 329 ms
90,252 KB
testcase_17 AC 77 ms
76,812 KB
testcase_18 AC 169 ms
83,664 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 1000000007
eps = 10**-9
inf = 10**9


def main():
    import sys
    input = sys.stdin.readline

    N = int(input())
    xyz = []
    val = set()
    for i in range(N):
        a, b, c = map(int, input().split())
        x, y, z = sorted([a, b, c])
        xyz.append((x, y, z, i))
        xyz.append((x, z, y, i))
        xyz.append((y, z, x, i))
        val.add(x)
        val.add(y)
    val.add(0)
    val = sorted(list(val))
    val2idx = {}
    for i, v in enumerate(val):
        val2idx[v] = i

    xyz.sort(key=lambda p: p[0])
    xyz.sort(key=lambda p: p[1])
    dp = [[-inf] * (len(val)) for _ in range(2**N)]
    dp[0][0] = 0
    for x, y, z, ii in xyz:
        j = val2idx[x]
        for state in range(2**N):
            if state >> ii & 1:
                continue
            for last in range(j+1):
                dp[state | (1 << ii)][j] = max(dp[state | (1 << ii)][j], dp[state][last] + z)
    ans = 0
    for state in range(2**N):
        for last in range(len(val)):
            ans = max(ans, dp[state][last])
    print(ans)


if __name__ == '__main__':
    main()
0