結果
| 問題 | No.90 品物の並び替え |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-04-25 14:19:56 |
| 言語 | Kotlin (2.1.0) |
| 結果 |
AC
|
| 実行時間 | 3,855 ms / 5,000 ms |
| コード長 | 726 bytes |
| 記録 | |
| コンパイル時間 | 15,299 ms |
| コンパイル使用メモリ | 440,700 KB |
| 実行使用メモリ | 151,616 KB |
| 最終ジャッジ日時 | 2024-11-20 18:03:41 |
| 合計ジャッジ時間 | 27,823 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 9 |
コンパイルメッセージ
Main.kt:12:85: warning: 'sumBy((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())
}