結果

問題 No.1360 [Zelkova 4th Tune] 協和音
ユーザー 👑 箱
提出日時 2021-01-22 22:13:38
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 574 ms / 2,000 ms
コード長 1,444 bytes
コンパイル時間 15,107 ms
コンパイル使用メモリ 419,804 KB
実行使用メモリ 57,048 KB
最終ジャッジ日時 2023-08-27 19:36:46
合計ジャッジ時間 42,022 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 288 ms
52,908 KB
testcase_01 AC 285 ms
52,828 KB
testcase_02 AC 289 ms
53,156 KB
testcase_03 AC 291 ms
53,092 KB
testcase_04 AC 289 ms
53,140 KB
testcase_05 AC 288 ms
53,168 KB
testcase_06 AC 288 ms
53,196 KB
testcase_07 AC 288 ms
53,204 KB
testcase_08 AC 287 ms
52,984 KB
testcase_09 AC 285 ms
52,728 KB
testcase_10 AC 288 ms
52,800 KB
testcase_11 AC 284 ms
53,196 KB
testcase_12 AC 285 ms
53,048 KB
testcase_13 AC 288 ms
53,252 KB
testcase_14 AC 292 ms
53,036 KB
testcase_15 AC 289 ms
53,012 KB
testcase_16 AC 289 ms
52,812 KB
testcase_17 AC 291 ms
52,992 KB
testcase_18 AC 288 ms
53,204 KB
testcase_19 AC 292 ms
52,924 KB
testcase_20 AC 290 ms
52,748 KB
testcase_21 AC 289 ms
52,956 KB
testcase_22 AC 297 ms
53,176 KB
testcase_23 AC 378 ms
56,240 KB
testcase_24 AC 368 ms
56,492 KB
testcase_25 AC 574 ms
56,412 KB
testcase_26 AC 324 ms
53,764 KB
testcase_27 AC 335 ms
53,788 KB
testcase_28 AC 568 ms
57,048 KB
testcase_29 AC 357 ms
53,916 KB
testcase_30 AC 381 ms
56,216 KB
testcase_31 AC 379 ms
56,692 KB
testcase_32 AC 411 ms
53,784 KB
testcase_33 AC 574 ms
56,900 KB
testcase_34 AC 533 ms
56,464 KB
testcase_35 AC 574 ms
56,752 KB
testcase_36 AC 535 ms
56,376 KB
testcase_37 AC 535 ms
56,636 KB
testcase_38 AC 534 ms
56,860 KB
testcase_39 AC 538 ms
56,624 KB
testcase_40 AC 532 ms
56,968 KB
testcase_41 AC 571 ms
56,600 KB
testcase_42 AC 535 ms
56,620 KB
testcase_43 AC 287 ms
53,184 KB
testcase_44 AC 494 ms
56,408 KB
testcase_45 AC 287 ms
52,848 KB
testcase_46 AC 485 ms
56,260 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.PrintWriter
import 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) continue
        val choice = BooleanArray(n) { false }
        for (j in 0 until n) {
            if (i.shr(j) % 2 != 0) {
                choice[j] = true
            }
        }
        var score = 0L
        for (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 Scanner
private 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
0