結果

問題 No.1360 [Zelkova 4th Tune] 協和音
ユーザー 👑 箱星箱星
提出日時 2021-01-22 22:11:17
言語 Kotlin
(1.9.23)
結果
WA  
実行時間 -
コード長 1,415 bytes
コンパイル時間 15,241 ms
コンパイル使用メモリ 418,416 KB
実行使用メモリ 56,980 KB
最終ジャッジ日時 2023-08-27 19:31:56
合計ジャッジ時間 41,048 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 304 ms
52,944 KB
testcase_01 AC 304 ms
53,092 KB
testcase_02 AC 308 ms
53,124 KB
testcase_03 AC 306 ms
53,084 KB
testcase_04 AC 310 ms
53,036 KB
testcase_05 AC 309 ms
53,656 KB
testcase_06 AC 315 ms
53,056 KB
testcase_07 AC 326 ms
53,108 KB
testcase_08 AC 303 ms
53,052 KB
testcase_09 AC 304 ms
53,080 KB
testcase_10 AC 306 ms
53,100 KB
testcase_11 AC 311 ms
53,136 KB
testcase_12 AC 315 ms
53,064 KB
testcase_13 AC 310 ms
53,352 KB
testcase_14 AC 307 ms
53,336 KB
testcase_15 AC 309 ms
53,336 KB
testcase_16 AC 311 ms
53,392 KB
testcase_17 AC 305 ms
53,084 KB
testcase_18 AC 306 ms
53,076 KB
testcase_19 AC 315 ms
53,336 KB
testcase_20 AC 312 ms
53,436 KB
testcase_21 AC 306 ms
53,460 KB
testcase_22 AC 310 ms
53,156 KB
testcase_23 AC 397 ms
56,272 KB
testcase_24 AC 385 ms
56,732 KB
testcase_25 AC 586 ms
56,928 KB
testcase_26 AC 336 ms
53,936 KB
testcase_27 AC 350 ms
53,884 KB
testcase_28 AC 546 ms
56,620 KB
testcase_29 AC 383 ms
54,220 KB
testcase_30 AC 401 ms
56,708 KB
testcase_31 AC 395 ms
56,252 KB
testcase_32 AC 378 ms
54,012 KB
testcase_33 AC 591 ms
56,716 KB
testcase_34 AC 551 ms
56,692 KB
testcase_35 AC 588 ms
56,708 KB
testcase_36 AC 552 ms
56,760 KB
testcase_37 AC 550 ms
56,632 KB
testcase_38 AC 552 ms
56,656 KB
testcase_39 AC 550 ms
56,652 KB
testcase_40 AC 550 ms
56,788 KB
testcase_41 AC 590 ms
56,980 KB
testcase_42 AC 557 ms
56,632 KB
testcase_43 AC 306 ms
53,036 KB
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
権限があれば一括ダウンロードができます

ソースコード

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)) {
        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