結果
問題 |
No.4 おもりと天秤
|
ユーザー |
![]() |
提出日時 | 2019-08-29 08:01:53 |
言語 | Kotlin (2.1.0) |
結果 |
AC
|
実行時間 | 624 ms / 5,000 ms |
コード長 | 899 bytes |
コンパイル時間 | 12,602 ms |
コンパイル使用メモリ | 428,540 KB |
実行使用メモリ | 88,096 KB |
最終ジャッジ日時 | 2024-11-20 19:26:58 |
合計ジャッジ時間 | 23,403 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 |
コンパイルメッセージ
Main.kt:1:10: warning: parameter 'args' is never used fun main(args: Array<String>){ ^ Main.kt:2:9: warning: variable 'weightCount' is never used val weightCount = readLine()!!.toInt() ^ Main.kt:4:30: warning: 'sumBy((T) -> Int): Int' is deprecated. Use sumOf instead. totalWeight = weightList.sumBy { it } ^
ソースコード
fun main(args: Array<String>){ val weightCount = readLine()!!.toInt() weightList = readLine()!!.split(" ").map { it.toInt() } totalWeight = weightList.sumBy { it } val ans = if(getAns(0, 0)) "possible" else "impossible" println(ans) } var weightList = listOf<Int>() var totalWeight = 0 val dic = mutableMapOf<Int, MutableMap<Int, Boolean>>() fun getAns(pos:Int, subTotal:Int):Boolean { if(subTotal * 2 == totalWeight) { return true } if(subTotal * 2 > totalWeight) { return false } if(pos > weightList.lastIndex) { return false } if(!dic.containsKey(pos)) { dic[pos] = mutableMapOf() } dic[pos]!![subTotal]?.let { return it } val ret1 = getAns(pos + 1, subTotal) val ret2 = getAns(pos + 1, subTotal + weightList[pos]) dic[pos]!![subTotal] = (ret1 || ret2) return (ret1 || ret2) }