結果
問題 | No.519 アイドルユニット |
ユーザー |
![]() |
提出日時 | 2025-03-31 17:28:11 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 182 ms / 1,000 ms |
コード長 | 1,204 bytes |
コンパイル時間 | 130 ms |
コンパイル使用メモリ | 82,736 KB |
実行使用メモリ | 195,968 KB |
最終ジャッジ日時 | 2025-03-31 17:29:46 |
合計ジャッジ時間 | 3,574 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 34 |
ソースコード
import sysn = int(sys.stdin.readline())f = [list(map(int, sys.stdin.readline().split())) for _ in range(n)]max_mask = 1 << ndp = [-1] * max_maskinitial_mask = (1 << n) - 1dp[initial_mask] = 0for mask in range(initial_mask, -1, -1):current_score = dp[mask]if current_score == -1:continue# Find the first available idol (a)lsb = mask & -maskif lsb == 0:continue # No bits seta = (lsb).bit_length() - 1# Remaining idols after aremaining_mask = mask >> (a + 1)current_j = a + 1 # Starting position in original maskwhile remaining_mask:lsb_j = remaining_mask & -remaining_maskif lsb_j == 0:breakoffset = (lsb_j).bit_length() - 1j = current_j + offsetif j >= n:break # Out of bounds# Calculate new mask and scorenew_mask = mask ^ ((1 << a) | (1 << j))added_score = f[a][j]new_total = current_score + added_scoreif new_total > dp[new_mask]:dp[new_mask] = new_total# Move to the next bitremaining_mask ^= lsb_jprint(dp[0])