結果

問題 No.1045 直方体大学
ユーザー tcltktcltk
提出日時 2021-05-19 04:22:24
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 3,155 bytes
コンパイル時間 178 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 228,628 KB
最終ジャッジ日時 2024-04-17 11:47:41
合計ジャッジ時間 6,266 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 139 ms
91,904 KB
testcase_01 AC 144 ms
86,656 KB
testcase_02 AC 141 ms
86,784 KB
testcase_03 AC 144 ms
86,656 KB
testcase_04 AC 140 ms
86,528 KB
testcase_05 AC 476 ms
94,636 KB
testcase_06 AC 536 ms
95,528 KB
testcase_07 AC 517 ms
95,528 KB
testcase_08 TLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#region Header
#!/usr/bin/env python3
# from typing import *

import sys
import io
import math
import collections
import decimal
import itertools
import bisect
import heapq


def input():
    return sys.stdin.readline()[:-1]


# sys.setrecursionlimit(1000000)
#endregion

# _INPUT = """5
# 94 61 65
# 36 14 63
# 54 96 47
# 78 69 73
# 32 82 99
# """
# sys.stdin = io.StringIO(_INPUT)

def is_loadable(lower1, lower2, upper1, upper2):
    return max(lower1, lower2) >= max(upper1, upper2) and min(lower1, lower2) >= min(upper1, upper2)


def main():
    N = int(input())
    Box = []
    for i in range(N):
        a, b, c = map(int, input().split())
        Box.append((a, b, c))
        # Box.append([(max(a, b), min(a, b)), (max(b, c), min(b, c)), (max(c, a), min(c, a))])

    # dp[i][0]: A[i], B[i]
    # dp[i][1]: B[i], C[i]
    # dp[i][2]: C[i], A[i]
    dp = [[[0] * 3 for _ in range(N)] for _ in range(1<<N)]
    
    for i in range(N):
        dp[1<<i][i][0] = Box[i][0]
        dp[1<<i][i][1] = Box[i][1]
        dp[1<<i][i][2] = Box[i][2]

    for s in range(1, 1<<N):
        for next_box in range(N):
            if s & (1<<next_box):
                continue
            s1 = s | (1<<next_box)
            
            for last_box in range(N):
                if not(s & (1<<last_box)):
                    continue
                
                Lower = Box[last_box]
                Upper = Box[next_box]

                dp[s1][last_box][0] = max(dp[s1][last_box][0], dp[s][last_box][0])
                dp[s1][last_box][1] = max(dp[s1][last_box][1], dp[s][last_box][1])
                dp[s1][last_box][2] = max(dp[s1][last_box][2], dp[s][last_box][2])
                if is_loadable(Lower[0], Lower[1], Upper[1], Upper[2]): dp[s1][next_box][0] = max(dp[s1][next_box][0], dp[s][last_box][2] + Upper[0])
                if is_loadable(Lower[1], Lower[2], Upper[1], Upper[2]): dp[s1][next_box][0] = max(dp[s1][next_box][0], dp[s][last_box][0] + Upper[0])
                if is_loadable(Lower[2], Lower[0], Upper[1], Upper[2]): dp[s1][next_box][0] = max(dp[s1][next_box][0], dp[s][last_box][1] + Upper[0])

                if is_loadable(Lower[0], Lower[1], Upper[2], Upper[0]): dp[s1][next_box][1] = max(dp[s1][next_box][1], dp[s][last_box][2] + Upper[1])
                if is_loadable(Lower[1], Lower[2], Upper[2], Upper[0]): dp[s1][next_box][1] = max(dp[s1][next_box][1], dp[s][last_box][0] + Upper[1])
                if is_loadable(Lower[2], Lower[0], Upper[2], Upper[0]): dp[s1][next_box][1] = max(dp[s1][next_box][1], dp[s][last_box][1] + Upper[1])

                if is_loadable(Lower[0], Lower[1], Upper[0], Upper[1]): dp[s1][next_box][2] = max(dp[s1][next_box][2], dp[s][last_box][2] + Upper[2])
                if is_loadable(Lower[1], Lower[2], Upper[0], Upper[1]): dp[s1][next_box][2] = max(dp[s1][next_box][2], dp[s][last_box][0] + Upper[2])
                if is_loadable(Lower[2], Lower[0], Upper[0], Upper[1]): dp[s1][next_box][2] = max(dp[s1][next_box][2], dp[s][last_box][1] + Upper[2])

    ans = max(max(dp[(1<<N)-1][i][k] for k in range(3)) for i in range(N))
    print(ans)

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