提出 #54841154


ソースコード 拡げる

import MutableIntMap.Companion.mutableIntMapOf
import java.io.*
import java.util.*
import kotlin.collections.*
import kotlin.math.*

val INPUT: InputStream = System.`in`
val OUTPUT: PrintStream = System.out

val _reader = INPUT.bufferedReader()

var _tokenizer: StringTokenizer = StringTokenizer("")
fun read(): String {
    while (!_tokenizer.hasMoreTokens()) {
        _tokenizer = StringTokenizer(_reader.readLine() ?: return "", " ")
    }
    return _tokenizer.nextToken()
}

fun readInt() = read().toInt()
fun readDouble() = read().toDouble()
fun readLong() = read().toLong()
fun readStrings(n: Int) = List(n) { read() }
fun readInts(n: Int) = List(n) { readInt() }
fun readIntArray(n: Int) = IntArray(n) { readInt() }
fun readDoubles(n: Int) = List(n) { readDouble() }
fun readDoubleArray(n: Int) = DoubleArray(n) { readDouble() }
fun readLongs(n: Int) = List(n) { readLong() }
fun readLongArray(n: Int) = LongArray(n) { readLong() }

val _writer = PrintWriter(OUTPUT, false)
inline fun output(block: PrintWriter.() -> Unit) {
    _writer.apply(block).flush()
}

class MutableIntMap<K> : LinkedHashMap<K, Int>() {
    override operator fun get(key: K): Int = super.get(key) ?: 0

    fun increment(key: K, value: Int = 1) {
        this[key] = this[key] + value
    }

    companion object {
        fun <K> mutableIntMapOf(vararg pairs: Pair<K, Int>) =
            MutableIntMap<K>().apply { putAll(pairs) }
    }
}

typealias Pii = Pair<Int, Int>

fun readPii() = readInt() to readInt()
fun readPiis(n: Int) = List(n) { readPii() }

infix fun Int.hasBit(i: Int): Boolean = this and (1 shl i) > 0
infix fun Int.xorBit(i: Int): Int = this xor (1 shl i)
infix fun Long.hasBit(i: Int): Boolean = this and (1L shl i) > 0
infix fun Long.xorBit(i: Int): Long = this xor (1L shl i)

fun largerStackSize(stackSizeMegaBytes: Int = 100, action: () -> Unit) {
    Thread(null, action, "", 1024L * 1024 * stackSizeMegaBytes).apply {
        start()
        join()
    }
}

// #################################################################################################

data class Node(
    val b: Long,
    val a: Long,
    val i: Int,
)

fun solve() {
    val n = readInt()
    val a = readLongs(n)
    var ans = a.sum()
    val p = PriorityQueue<Node>(compareBy { it.b })
    for (i in a) p += Node(i * 3, i, 2)
    repeat(n - 2) {
        val t = p.poll()
//        println("! $t")
        ans += t.b
        p += Node(t.a * (t.i * 2 + 1), t.a, t.i + 1)
    }
    println(ans)
}

fun main() {
//    repeat(readInt()) { solve() }
    solve()
}

提出情報

提出日時
問題 F - Tree Degree Optimization
ユーザ wangchaohui
言語 Kotlin (Kotlin/JVM 1.8.20)
得点 550
コード長 2640 Byte
結果 AC
実行時間 478 ms
メモリ 77424 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 550 / 550
結果
AC × 3
AC × 29
セット名 テストケース
Sample 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt
All 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 01_test_01.txt, 01_test_02.txt, 01_test_03.txt, 01_test_04.txt, 01_test_05.txt, 01_test_06.txt, 01_test_07.txt, 01_test_08.txt, 01_test_09.txt, 01_test_10.txt, 01_test_11.txt, 01_test_12.txt, 01_test_13.txt, 01_test_14.txt, 01_test_15.txt, 01_test_16.txt, 01_test_17.txt, 01_test_18.txt, 01_test_19.txt, 01_test_20.txt, 01_test_21.txt, 01_test_22.txt, 01_test_23.txt, 01_test_24.txt, 01_test_25.txt, 01_test_26.txt
ケース名 結果 実行時間 メモリ
00_sample_01.txt AC 56 ms 38992 KiB
00_sample_02.txt AC 59 ms 39220 KiB
00_sample_03.txt AC 60 ms 39064 KiB
01_test_01.txt AC 390 ms 75436 KiB
01_test_02.txt AC 401 ms 76096 KiB
01_test_03.txt AC 400 ms 74192 KiB
01_test_04.txt AC 455 ms 77308 KiB
01_test_05.txt AC 401 ms 77424 KiB
01_test_06.txt AC 456 ms 77392 KiB
01_test_07.txt AC 405 ms 76820 KiB
01_test_08.txt AC 478 ms 75668 KiB
01_test_09.txt AC 420 ms 75452 KiB
01_test_10.txt AC 470 ms 76824 KiB
01_test_11.txt AC 450 ms 75108 KiB
01_test_12.txt AC 447 ms 73820 KiB
01_test_13.txt AC 414 ms 72672 KiB
01_test_14.txt AC 352 ms 61404 KiB
01_test_15.txt AC 337 ms 61384 KiB
01_test_16.txt AC 318 ms 60444 KiB
01_test_17.txt AC 383 ms 70108 KiB
01_test_18.txt AC 339 ms 66644 KiB
01_test_19.txt AC 338 ms 68064 KiB
01_test_20.txt AC 346 ms 66904 KiB
01_test_21.txt AC 294 ms 60460 KiB
01_test_22.txt AC 346 ms 75532 KiB
01_test_23.txt AC 59 ms 39084 KiB
01_test_24.txt AC 59 ms 38804 KiB
01_test_25.txt AC 57 ms 38812 KiB
01_test_26.txt AC 373 ms 77124 KiB