結果
問題 | No.1045 直方体大学 |
ユーザー | rlangevin |
提出日時 | 2023-02-13 23:46:47 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,023 bytes |
コンパイル時間 | 299 ms |
コンパイル使用メモリ | 86,712 KB |
実行使用メモリ | 109,336 KB |
最終ジャッジ日時 | 2023-09-23 14:15:37 |
合計ジャッジ時間 | 23,620 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 68 ms
70,864 KB |
testcase_01 | AC | 67 ms
70,636 KB |
testcase_02 | AC | 78 ms
75,772 KB |
testcase_03 | AC | 80 ms
75,620 KB |
testcase_04 | AC | 77 ms
75,676 KB |
testcase_05 | AC | 153 ms
78,240 KB |
testcase_06 | AC | 159 ms
78,684 KB |
testcase_07 | AC | 156 ms
78,260 KB |
testcase_08 | TLE | - |
testcase_09 | TLE | - |
testcase_10 | TLE | - |
testcase_11 | TLE | - |
testcase_12 | TLE | - |
testcase_13 | TLE | - |
testcase_14 | TLE | - |
testcase_15 | TLE | - |
testcase_16 | TLE | - |
testcase_17 | AC | 105 ms
77,288 KB |
testcase_18 | AC | 1,482 ms
108,224 KB |
ソースコード
N = int(input()) D = [] for i in range(N): D.append(list(map(int, input().split()))) N2 = 1 << N inf = 10 ** 18 dp = [[-inf] * (N * 3) for i in range(N2)] ans = 0 for i in range(N): for k in range(3): dp[1 << i][i * 3 + k] = D[i][k] ans = max(ans, dp[1 << i][i * 3 + k]) def check(i, j, a, b): if D[i][(a + 1) % 3] <= D[j][(b + 1) % 3] and D[i][(a + 2) % 3] <= D[j][(b + 2) % 3]: return True if D[i][(a + 2) % 3] <= D[j][(b + 1) % 3] and D[i][(a + 1) % 3] <= D[j][(b + 2) % 3]: return True return False for s in range(1, N2): for p in range(3 * N): q, r = divmod(p, 3) if (s >> q) & 1 == 0: continue for i in range(N): if (s >> i) & 1: continue for k in range(3): if check(q, i, r, k): dp[s | (1 << i)][3 * i + k] = max(dp[s | (1 << i)][3 * i + k], dp[s][p] + D[i][k]) ans = max(ans, dp[s | (1 << i)][3 * i + k]) print(ans)