結果
問題 | No.1360 [Zelkova 4th Tune] 協和音 |
ユーザー |
![]() |
提出日時 | 2025-03-26 15:45:21 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 559 ms / 2,000 ms |
コード長 | 912 bytes |
コンパイル時間 | 144 ms |
コンパイル使用メモリ | 82,600 KB |
実行使用メモリ | 76,588 KB |
最終ジャッジ日時 | 2025-03-26 15:46:06 |
合計ジャッジ時間 | 11,339 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 47 |
ソースコード
n = int(input()) a = list(map(int, input().split())) b = [list(map(int, input().split())) for _ in range(n)] max_score = -float('inf') best_mask = 0 for mask in range(1, 1 << n): current_a = 0 current_b = 0 # Calculate sum of A's for i in range(n): if mask & (1 << i): current_a += a[i] # Calculate sum of B's for i in range(n): if mask & (1 << i): for j in range(i + 1, n): if mask & (1 << j): current_b += b[i][j] total = current_a + current_b if total > max_score: max_score = total best_mask = mask elif total == max_score and bin(mask).count('1') < bin(best_mask).count('1'): best_mask = mask # Prepare the result result = [] for i in range(n): if best_mask & (1 << i): result.append(i + 1) result.sort() print(max_score) print(' '.join(map(str, result)))