結果
| 問題 | No.90 品物の並び替え |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-04-25 14:19:56 |
| 言語 | Kotlin (2.3.20) |
| 結果 |
AC
|
| 実行時間 | 3,390 ms / 5,000 ms |
| コード長 | 726 bytes |
| 記録 | |
| コンパイル時間 | 11,679 ms |
| コンパイル使用メモリ | 480,552 KB |
| 実行使用メモリ | 150,100 KB |
| 最終ジャッジ日時 | 2026-05-14 21:27:30 |
| 合計ジャッジ時間 | 20,777 ms |
|
ジャッジサーバーID (参考情報) |
judge3_1 / judge2_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 9 |
コンパイルメッセージ
Main.kt:12:85: warning: 'fun <T> Iterable<T>.sumBy(selector: (T) -> Int): Int' is deprecated. Use sumOf instead.
return scores.filter { itemMap.get(it.first)!! < itemMap.get(it.second)!! }.sumBy { it.third }
^^^^^
Main.kt:17:98: warning: unnecessary non-null assertion (!!) on a non-null receiver of type 'Int'.
false -> (0 until n).filter { !items.contains(it) }.map { getMaxScore(*items, it) }.max()!!
^^
ソースコード
package yukicoder
fun main() {
val (n, m) = readLine()!!.split(" ").map(String::toInt)
val scores = (0 until m).map {
val (item1, item2, score) = readLine()!!.split(" ").map(String::toInt)
Triple(item1, item2, score)
}
fun getScore(items: IntArray): Int {
val itemMap: Map<Int, Int> = items.mapIndexed { index, i -> i to index }.toMap()
return scores.filter { itemMap.get(it.first)!! < itemMap.get(it.second)!! }.sumBy { it.third }
}
fun getMaxScore(vararg items: Int): Int = when (items.size >= n) {
true -> getScore(items)
false -> (0 until n).filter { !items.contains(it) }.map { getMaxScore(*items, it) }.max()!!
}
println(getMaxScore())
}