結果

問題 No.1045 直方体大学
ユーザー pekempeypekempey
提出日時 2020-05-01 22:37:23
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,369 bytes
コンパイル時間 91 ms
コンパイル使用メモリ 10,920 KB
実行使用メモリ 34,028 KB
最終ジャッジ日時 2023-08-26 15:20:10
合計ジャッジ時間 5,788 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
34,028 KB
testcase_01 AC 138 ms
29,808 KB
testcase_02 AC 121 ms
29,776 KB
testcase_03 AC 122 ms
29,732 KB
testcase_04 AC 124 ms
29,796 KB
testcase_05 AC 210 ms
29,932 KB
testcase_06 AC 199 ms
29,828 KB
testcase_07 AC 194 ms
29,876 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 #

def input_int():
    return int(input())

def input_ints():
    return list(map(int, input().split()))

import numpy as np

N = input_int()
A = []
B = []
C = []
for _ in range(N):
    a, b, c = sorted(input_ints())
    A.append(a)
    B.append(b)
    C.append(c)

# 0: AB
# 1: AC
# 2: BC

def height(k):
    i, j = divmod(k, 3)
    if j == 0:
        return C[i]
    elif j == 1:
        return B[i]
    else:
        return A[i]

def face(k):
    i, j = divmod(k, 3)
    if j == 0:
        return A[i], B[i]
    elif j == 1:
        return A[i], C[i]
    else:
        return B[i], C[i]

INF = 10**9
dp = np.full((1 << N, N * 3), -INF, dtype=np.int32)
for i in range(N):
    dp[1 << i][i * 3 + 0] = height(i * 3 + 0)
    dp[1 << i][i * 3 + 1] = height(i * 3 + 1)
    dp[1 << i][i * 3 + 2] = height(i * 3 + 2)

def can(x, y):
    f1 = face(x)
    f2 = face(y)
    return f1[0] <= f2[0] and f1[1] <= f2[1]

g = [[can(i, j) for j in range(N * 3)] for i in range(N * 3)]

ans = 0
for i in range(1 << N):
    for j in range(N * 3):
        if dp[i][j] == -INF:
            continue
        ans = max(ans, dp[i][j])
        for kx in range(N):
            if i >> kx & 1: continue
            for ky in range(3):
                k = kx * 3 + ky
                if g[j][k]:
                    dp[i | 1 << kx][k] = max(dp[i | 1 << kx][k], dp[i][j] + height(k))

print(ans)


0