結果
| 問題 |
No.115 遠足のおやつ
|
| コンテスト | |
| ユーザー |
バカらっく
|
| 提出日時 | 2019-10-01 08:17:28 |
| 言語 | Kotlin (2.1.0) |
| 結果 |
AC
|
| 実行時間 | 735 ms / 5,000 ms |
| コード長 | 1,215 bytes |
| コンパイル時間 | 16,268 ms |
| コンパイル使用メモリ | 473,964 KB |
| 実行使用メモリ | 104,372 KB |
| 最終ジャッジ日時 | 2025-01-03 01:52:35 |
| 合計ジャッジ時間 | 33,749 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 40 |
ソースコード
fun main(arr:Array<String>) {
val(n,d,k) = readLine()!!.split(" ").map { it.toInt() }
itemCount = n
val ans = getAns(1, d, k)
println(ans.joinToString(" "))
}
var itemCount = 0
val dic = mutableMapOf<Int, MutableMap<Int, MutableMap<Int, List<Int>>>>()
fun getAns(index:Int, remain:Int, remainCount:Int):MutableList<Int> {
if(remain == 0) {
if(remainCount == 0) {
return mutableListOf()
} else {
return mutableListOf(-1)
}
}
if(remainCount <= 0) {
return mutableListOf(-1)
}
if(index > itemCount) {
return mutableListOf(-1)
}
if(remain < 0) {
return mutableListOf(-1)
}
dic[index]?: run { dic[index] = mutableMapOf() }
dic[index]!![remain]?: run { dic[index]!![remain] = mutableMapOf() }
dic[index]!![remain]!![remainCount]?.let { return it.toMutableList() }
var ret = getAns(index + 1, remain - index, remainCount - 1)
if(ret.isEmpty() || ret[0] != -1) {
ret = ret.map { it }.toMutableList()
ret.add(0, index)
} else {
ret = getAns(index + 1, remain, remainCount)
}
dic[index]!![remain]!![remainCount] = ret.map { it }
return ret
}
バカらっく