結果

問題 No.45 回転寿司
ユーザー バカらっく
提出日時 2021-11-10 10:04:36
言語 Kotlin
(2.4.21 + ACL)
コンパイル:
kotlinc -cp /opt/aclib/ac_library.jar _filename_ -include-runtime -d main.jar
実行:
java -cp main.jar:/opt/aclib/ac_library.jar _class_
結果
AC  
実行時間 99 ms / 5,000 ms
+ 759µs
コード長 914 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 7,897 ms
コンパイル使用メモリ 501,724 KB
実行使用メモリ 47,368 KB
最終ジャッジ日時 2026-09-27 04:05:14
合計ジャッジ時間 13,482 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge4_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import java.util.*

fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val v = readLine()!!.split(" ").map { it.toInt() }

    val flag = arrayOfNulls<Int?>(n)

    val task = Stack<Int>()
    task.add(0)
    while (task.isNotEmpty()) {
        val current = task.pop()
        if(current == v.lastIndex) {
            flag[current] = v[current]
            continue
        }
        if(current == v.lastIndex - 1) {
            flag[current] = Math.max(v[current], v[current+1])
            continue
        }
        if(flag[current + 1] == null) {
            task.add(current)
            task.add(current + 1)
            continue
        }
        if(flag[current + 2] == null) {
            task.add(current)
            task.add(current + 2)
            continue
        }
        flag[current] = Math.max(flag[current+1]!!, flag[current+2]!! + v[current])
    }
    println(flag[0]!!)
}
0