結果

問題 No.90 品物の並び替え
コンテスト
ユーザー komkomh
提出日時 2019-04-24 17:19:38
言語 Kotlin
(2.3.20)
コンパイル:
kotlinc _filename_ -include-runtime -d main.jar
実行:
kotlin main.jar
結果
TLE  
実行時間 -
コード長 710 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 10,006 ms
コンパイル使用メモリ 482,852 KB
実行使用メモリ 148,908 KB
最終ジャッジ日時 2026-05-14 21:28:29
合計ジャッジ時間 30,517 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 8 TLE * 1
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:12:78: warning: 'fun <T> Iterable<T>.sumBy(selector: (T) -> Int): Int' is deprecated. Use sumOf instead.
        scores.filter { items.indexOf(it.first) < items.indexOf(it.second) }.sumBy { it.third }
                                                                             ^^^^^
Main.kt:17:97: warning: unnecessary non-null assertion (!!) on a non-null receiver of type 'Int'.
            false -> (0..n).filter { !items.contains(it) }.map { getMaxScore(*items, it) }.max()!!
                                                                                                ^^

ソースコード

diff #
raw source code

package yukicoder

fun main() {
    val (n, m) = readLine()!!.split(" ").map(String::toInt)
    val scores = mutableSetOf<Triple<Int, Int, Int>>()
    (0 until m).forEach {
        val (item1, item2, score) = readLine()!!.split(" ").map(String::toInt)
        scores.add(Triple(item1, item2, score))
    }

    fun getScore(items: IntArray): Int =
        scores.filter { items.indexOf(it.first) < items.indexOf(it.second) }.sumBy { it.third }

    fun getMaxScore(vararg items: Int): Int {
        return when (items.size >= n) {
            true -> getScore(items)
            false -> (0..n).filter { !items.contains(it) }.map { getMaxScore(*items, it) }.max()!!
        }
    }
    println(getMaxScore())
}
0