結果

問題 No.842 初詣
ユーザー 14番14番
提出日時 2022-07-06 10:41:21
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 319 ms / 2,000 ms
コード長 737 bytes
コンパイル時間 14,668 ms
コンパイル使用メモリ 421,696 KB
実行使用メモリ 57,564 KB
最終ジャッジ日時 2023-08-23 06:56:58
合計ジャッジ時間 22,913 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 314 ms
57,564 KB
testcase_01 AC 312 ms
57,076 KB
testcase_02 AC 311 ms
57,008 KB
testcase_03 AC 314 ms
56,956 KB
testcase_04 AC 316 ms
57,016 KB
testcase_05 AC 315 ms
57,360 KB
testcase_06 AC 310 ms
56,956 KB
testcase_07 AC 313 ms
56,996 KB
testcase_08 AC 313 ms
56,996 KB
testcase_09 AC 313 ms
57,152 KB
testcase_10 AC 315 ms
57,008 KB
testcase_11 AC 312 ms
57,096 KB
testcase_12 AC 313 ms
57,144 KB
testcase_13 AC 313 ms
57,436 KB
testcase_14 AC 310 ms
57,212 KB
testcase_15 AC 311 ms
57,312 KB
testcase_16 AC 308 ms
56,956 KB
testcase_17 AC 319 ms
57,120 KB
testcase_18 AC 316 ms
56,968 KB
testcase_19 AC 312 ms
57,432 KB
testcase_20 AC 310 ms
57,316 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:1:10: warning: parameter 'args' is never used
fun main(args: Array<String>) {
         ^

ソースコード

diff #

fun main(args: Array<String>) {
    val inpt = readLine()!!.split(" ").map { it.toInt() }
    var remain = inpt.last()
    val coins = inpt.dropLast(1).toIntArray()
    println(if(Solve(remain,coins).getAns()) "YES" else "NO")
}

class Solve(private val amount:Int, private val coins:IntArray) {
    private val coinType = listOf(500,100,50,10,5,1)
    fun getAns():Boolean {
        return getAns(0, amount)
    }
    private fun getAns(index:Int, remain:Int):Boolean {
        if(remain == 0) {
            return true
        }
        if(index > coins.lastIndex) {
            return false
        }
        val cnt = Math.min(remain/coinType[index], coins[index])
        return getAns(index+1, remain - cnt*coinType[index])
    }
}
0