結果

問題 No.30 たこやき工場
ユーザー バカらっくバカらっく
提出日時 2019-09-05 16:08:40
言語 Kotlin
(1.9.23)
結果
TLE  
実行時間 -
コード長 978 bytes
コンパイル時間 26,094 ms
コンパイル使用メモリ 426,712 KB
実行使用メモリ 61,496 KB
最終ジャッジ日時 2023-09-02 11:52:14
合計ジャッジ時間 31,112 ms
ジャッジサーバーID
(参考情報)
judge16 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 340 ms
57,064 KB
testcase_01 AC 340 ms
57,064 KB
testcase_02 AC 336 ms
57,188 KB
testcase_03 AC 332 ms
56,968 KB
testcase_04 AC 332 ms
58,996 KB
testcase_05 AC 335 ms
56,892 KB
testcase_06 AC 355 ms
57,108 KB
testcase_07 AC 354 ms
56,928 KB
testcase_08 AC 468 ms
57,908 KB
testcase_09 AC 369 ms
57,112 KB
testcase_10 TLE -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:3:10: warning: parameter 'arr' is never used
fun main(arr:Array<String>) {
         ^

ソースコード

diff #

import java.util.*

fun main(arr:Array<String>) {
    val zairyoCount = readLine()!!.toInt()
    val seizouCount = readLine()!!.toInt()
    val need = Array<Int>(zairyoCount + 1, {0})

    val seizou = mutableMapOf<Int, MutableMap<Int, Int>>()
    (1..seizouCount).forEach {
        val (zairyo, value, dekiru) = readLine()!!.split(" ").map { it.toInt() }
        if(!seizou.containsKey(dekiru)) {
            seizou[dekiru] = mutableMapOf()
        }
        seizou[dekiru]!![zairyo] = value
    }

    val queue = LinkedList<Task>()
    queue.push(Task(zairyoCount, 1))
    while (queue.isNotEmpty()) {
        val task = queue.pop()
        seizou[task.target]?.also {
            it.forEach {
                queue.push(Task(it.key, it.value * task.value))
            }
        } ?: run {
            need[task.target] =  need[task.target] + task.value
        }
    }

    need.drop(1).dropLast(1).forEach { println(it) }
}

data class Task(val target:Int, val value:Int)
0