結果

問題 No.1045 直方体大学
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2022-03-27 22:47:24
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,138 ms / 2,000 ms
コード長 1,212 bytes
コンパイル時間 188 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 184,204 KB
最終ジャッジ日時 2024-04-24 08:01:39
合計ジャッジ時間 6,940 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
52,352 KB
testcase_01 AC 38 ms
52,352 KB
testcase_02 AC 39 ms
52,864 KB
testcase_03 AC 38 ms
52,608 KB
testcase_04 AC 37 ms
52,864 KB
testcase_05 AC 95 ms
77,440 KB
testcase_06 AC 92 ms
77,568 KB
testcase_07 AC 103 ms
77,568 KB
testcase_08 AC 472 ms
183,236 KB
testcase_09 AC 409 ms
182,216 KB
testcase_10 AC 389 ms
182,088 KB
testcase_11 AC 420 ms
182,460 KB
testcase_12 AC 485 ms
182,916 KB
testcase_13 AC 474 ms
182,928 KB
testcase_14 AC 440 ms
183,224 KB
testcase_15 AC 603 ms
184,024 KB
testcase_16 AC 617 ms
184,204 KB
testcase_17 AC 78 ms
74,112 KB
testcase_18 AC 1,138 ms
181,248 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
ABC = [list(map(int,input().split())) for i in range(n)]

dp = [[[0]*3 for i in range(n)] for j in range(1<<n)]
for i,(a,b,c) in enumerate(ABC):
    dp[1<<i][i][0] = c
    dp[1<<i][i][1] = b
    dp[1<<i][i][2] = a

ans = 0
for bit in range(1<<n):
    for j in range(n):
        a,b,c = ABC[j]
        for k in range(3):
            h = dp[bit][j][k]
            
            ans = max(ans,h)
            if h == 0:
                continue

            for t in range(n):
                if bit >> t & 1:
                    continue

                if k == 0:
                    x,y = a,b
                elif k == 1:
                    x,y = a,c
                else:
                    x,y = b,c
                

                na,nb,nc = ABC[t]
                if (na <= x and nb <= y) or (na <= y and nb <= x):
                    dp[bit|1<<t][t][0] = max(dp[bit|1<<t][t][0],h+nc)

                if (na <= x and nc <= y) or (na <= y and nc <= x):
                    dp[bit|1<<t][t][1] = max(dp[bit|1<<t][t][1],h+nb)
                if (nb <= x and nc <= y) or (nb <= y and nc <= x):
                    dp[bit|1<<t][t][2] = max(dp[bit|1<<t][t][2],h+na)

print(ans)
                
0