Submission #46366094


Source Code Expand

import java.util.TreeMap
import kotlin.math.pow

fun main() {
    val n = readln().toInt()
    val sc = Array(n) {
        readln().split(" ").map { it.toLong() }.toLongArray()
    }
        .sortedBy { it[0] }

    val treeMap = TreeMap<Long, Long>()
    for((s, c) in sc) {
        treeMap[s] = c
    }

    val ans = process(treeMap)
    println(ans)
}

fun process(treeMap: TreeMap<Long, Long>): Long {
    var count = 0L

    while(treeMap.isNotEmpty()) {
        val (s, c) = treeMap.firstEntry()

        if(c < 2) {
            count += c
            treeMap.remove(s)
            continue
        }

        val num = countDiv(c)

        val mul = s * num
        treeMap[mul] = treeMap.getOrDefault(mul, 0) + 1

        treeMap[s] = c - num
    }
    return count
}

fun countDiv(n: Long): Long {
    var num = n

    var count = 0
    while (true) {
        num /= 2
        if(num == 0L) {
            break
        }
        count++
    }
    return 2.0.pow(count).toLong()
}

Submission Info

Submission Time
Task D - Merge Slimes
User dhirabayashi
Language Kotlin (Kotlin/JVM 1.8.20)
Score 425
Code Size 1044 Byte
Status AC
Exec Time 2692 ms
Memory 287848 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 425 / 425
Status
AC × 3
AC × 33
Set Name Test Cases
Sample example_00.txt, example_01.txt, example_02.txt
All example_00.txt, example_01.txt, example_02.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, hand_08.txt, hand_09.txt, hand_10.txt, hand_11.txt, hand_12.txt, hand_13.txt, hand_14.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt
Case Name Status Exec Time Memory
example_00.txt AC 71 ms 43312 KiB
example_01.txt AC 71 ms 43416 KiB
example_02.txt AC 69 ms 42812 KiB
hand_00.txt AC 1109 ms 88760 KiB
hand_01.txt AC 1486 ms 133192 KiB
hand_02.txt AC 1726 ms 165132 KiB
hand_03.txt AC 1407 ms 149140 KiB
hand_04.txt AC 1157 ms 89332 KiB
hand_05.txt AC 73 ms 43124 KiB
hand_06.txt AC 76 ms 43120 KiB
hand_07.txt AC 752 ms 77132 KiB
hand_08.txt AC 73 ms 43152 KiB
hand_09.txt AC 71 ms 43332 KiB
hand_10.txt AC 762 ms 83908 KiB
hand_11.txt AC 1673 ms 183420 KiB
hand_12.txt AC 2692 ms 287848 KiB
hand_13.txt AC 2665 ms 257620 KiB
hand_14.txt AC 729 ms 83044 KiB
random_00.txt AC 1449 ms 102004 KiB
random_01.txt AC 1624 ms 109380 KiB
random_02.txt AC 1684 ms 112904 KiB
random_03.txt AC 1717 ms 113976 KiB
random_04.txt AC 1725 ms 115804 KiB
random_05.txt AC 1787 ms 117892 KiB
random_06.txt AC 630 ms 77864 KiB
random_07.txt AC 652 ms 80668 KiB
random_08.txt AC 2079 ms 166720 KiB
random_09.txt AC 1973 ms 157032 KiB
random_10.txt AC 1959 ms 157176 KiB
random_11.txt AC 2079 ms 183128 KiB
random_12.txt AC 1892 ms 156328 KiB
random_13.txt AC 1900 ms 158784 KiB
random_14.txt AC 1992 ms 181308 KiB