結果

問題 No.45 回転寿司
ユーザー バカらっくバカらっく
提出日時 2019-09-09 18:05:44
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 314 ms / 5,000 ms
コード長 591 bytes
コンパイル時間 13,772 ms
コンパイル使用メモリ 427,172 KB
実行使用メモリ 53,672 KB
最終ジャッジ日時 2023-09-10 21:55:17
合計ジャッジ時間 26,342 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 309 ms
53,480 KB
testcase_01 AC 308 ms
53,428 KB
testcase_02 AC 310 ms
53,060 KB
testcase_03 AC 311 ms
53,140 KB
testcase_04 AC 310 ms
53,036 KB
testcase_05 AC 300 ms
53,028 KB
testcase_06 AC 307 ms
53,384 KB
testcase_07 AC 310 ms
53,112 KB
testcase_08 AC 303 ms
53,076 KB
testcase_09 AC 308 ms
52,944 KB
testcase_10 AC 305 ms
53,128 KB
testcase_11 AC 303 ms
53,496 KB
testcase_12 AC 311 ms
53,096 KB
testcase_13 AC 303 ms
52,964 KB
testcase_14 AC 299 ms
53,108 KB
testcase_15 AC 311 ms
53,164 KB
testcase_16 AC 310 ms
53,044 KB
testcase_17 AC 311 ms
52,964 KB
testcase_18 AC 304 ms
53,412 KB
testcase_19 AC 314 ms
53,148 KB
testcase_20 AC 294 ms
52,968 KB
testcase_21 AC 302 ms
53,032 KB
testcase_22 AC 304 ms
53,028 KB
testcase_23 AC 300 ms
52,996 KB
testcase_24 AC 294 ms
52,908 KB
testcase_25 AC 293 ms
52,924 KB
testcase_26 AC 310 ms
53,672 KB
testcase_27 AC 311 ms
53,116 KB
testcase_28 AC 312 ms
53,076 KB
testcase_29 AC 310 ms
53,168 KB
testcase_30 AC 308 ms
53,072 KB
testcase_31 AC 309 ms
53,268 KB
testcase_32 AC 295 ms
52,984 KB
testcase_33 AC 312 ms
53,060 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:1:10: warning: parameter 'arr' is never used
fun main(arr:Array<String>) {
         ^
Main.kt:2:9: warning: variable 'susiCount' is never used
    val susiCount = readLine()!!.toInt()
        ^
Main.kt:17:38: warning: unnecessary non-null assertion (!!) on a non-null receiver of type Int
        return susiList.take(2).max()!!
                                     ^

ソースコード

diff #

fun main(arr:Array<String>) {
    val susiCount = readLine()!!.toInt()
    susiList.addAll(readLine()!!.split(" ").map { it.toInt() })
    susiList.indices.forEach { getAns(it) }
    println(getAns(susiList.lastIndex))
}

val susiList = mutableListOf<Int>()

val dic = mutableMapOf<Int, Int>()

fun getAns(idx:Int):Int {
    if(idx == 0) {
        return susiList[0]
    }
    if(idx == 1) {
        return susiList.take(2).max()!!
    }

    dic[idx]?.let { return it }
    var ans = getAns(idx - 1)
    ans = Math.max(getAns(idx-2) + susiList[idx], ans)
    dic[idx] = ans
    return ans
}
0