結果

問題 No.1045 直方体大学
ユーザー pekempeypekempey
提出日時 2020-05-01 22:54:06
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,296 ms / 2,000 ms
コード長 1,454 bytes
コンパイル時間 981 ms
コンパイル使用メモリ 86,992 KB
実行使用メモリ 102,636 KB
最終ジャッジ日時 2023-08-26 15:36:24
合計ジャッジ時間 5,321 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,388 KB
testcase_01 AC 73 ms
71,404 KB
testcase_02 AC 74 ms
71,352 KB
testcase_03 AC 75 ms
71,392 KB
testcase_04 AC 75 ms
71,392 KB
testcase_05 AC 121 ms
78,044 KB
testcase_06 AC 114 ms
78,096 KB
testcase_07 AC 107 ms
77,804 KB
testcase_08 AC 205 ms
102,636 KB
testcase_09 AC 180 ms
102,568 KB
testcase_10 AC 165 ms
102,380 KB
testcase_11 AC 179 ms
102,464 KB
testcase_12 AC 207 ms
102,396 KB
testcase_13 AC 228 ms
102,580 KB
testcase_14 AC 189 ms
102,376 KB
testcase_15 AC 218 ms
102,616 KB
testcase_16 AC 294 ms
102,372 KB
testcase_17 AC 121 ms
77,496 KB
testcase_18 AC 1,296 ms
102,180 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

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:


        k
        return A[i], C[i]
    else:
        return B[i], C[i]

INF = 10**9
dp = [-INF] * ((1 << N) * (N * 3))

def get(i, j):
    return dp[i * (N * 3) + j]

def update(i, j, v):
    k = i * (N * 3) + j
    dp[k] = max(dp[k], v)

for i in range(N):
    update(1 << i, i * 3 + 0, height(i * 3 + 0))
    update(1 << i, i * 3 + 1, height(i * 3 + 1))
    update(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 get(i, j) == -INF:
            continue
        ans = max(ans, get(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]:
                    update(i | 1 << kx, k, get(i, j) + height(k))
print(ans)


0