結果
問題 | No.1360 [Zelkova 4th Tune] 協和音 |
ユーザー |
|
提出日時 | 2021-01-22 22:13:38 |
言語 | Kotlin (2.1.0) |
結果 |
AC
|
実行時間 | 676 ms / 2,000 ms |
コード長 | 1,444 bytes |
コンパイル時間 | 15,085 ms |
コンパイル使用メモリ | 443,400 KB |
実行使用メモリ | 63,692 KB |
最終ジャッジ日時 | 2024-12-28 01:39:49 |
合計ジャッジ時間 | 40,766 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 47 |
ソースコード
import java.io.PrintWriterimport java.util.*import kotlin.math.*fun PrintWriter.solve() {val n = nextInt()val a = Array(n) { nextLong() }val b = Array(n) { Array(n) { nextLong() } }var ans = -1L to BooleanArray(n) { false }for (i in 0 until 1.shl(n)) {if (i == 0) continueval choice = BooleanArray(n) { false }for (j in 0 until n) {if (i.shr(j) % 2 != 0) {choice[j] = true}}var score = 0Lfor (j in 0 until n) {if (choice[j]) score += a[j]}for (j in 0 until n) {for (k in j + 1 until n) {if (choice[j] && choice[k]) {score += b[j][k]}}}if (ans.first < score) {ans = score to choice}}println(ans.first)println((0 until n).filter { ans.second[it] }.map { it + 1 }.joinToString(" "))}fun main() {val writer = PrintWriter(System.out, false)writer.solve()writer.flush()}// region Scannerprivate var st = StringTokenizer("")private val br = System.`in`.bufferedReader()fun next(): String {while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())return st.nextToken()}fun nextInt() = next().toInt()fun nextLong() = next().toLong()fun nextLine() = br.readLine()!!fun nextDouble() = next().toDouble()// endregion