結果
問題 |
No.519 アイドルユニット
|
ユーザー |
![]() |
提出日時 | 2025-03-20 21:18:01 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,211 bytes |
コンパイル時間 | 196 ms |
コンパイル使用メモリ | 82,632 KB |
実行使用メモリ | 349,040 KB |
最終ジャッジ日時 | 2025-03-20 21:19:04 |
合計ジャッジ時間 | 4,710 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | TLE * 1 -- * 33 |
ソースコード
n = int(input()) F = [] for _ in range(n): F.append(list(map(int, input().split()))) max_mask = 1 << n dp = [-1] * max_mask dp[0] = 0 # Precompute masks for each bit count precomputed_masks = [[] for _ in range(n + 1)] for mask in range(max_mask): bc = bin(mask).count('1') precomputed_masks[bc].append(mask) for bc in range(0, n + 1, 2): for mask in precomputed_masks[bc]: if dp[mask] == -1: continue # Find the first unused idol using bitwise operations not_mask = (~mask) & ((1 << n) - 1) if not_mask == 0: continue lsb = not_mask & -not_mask first = (lsb).bit_length() - 1 # Generate all possible pairs with the first unused idol not_mask_j = not_mask & (~((1 << (first + 1)) - 1)) remaining = not_mask_j while remaining: lsb_j = remaining & -remaining j = (lsb_j).bit_length() - 1 remaining ^= lsb_j new_mask = mask | (1 << first) | (1 << j) new_score = dp[mask] + F[first][j] if new_score > dp[new_mask]: dp[new_mask] = new_score print(dp[(1 << n) - 1])