結果

問題 No.45 回転寿司
ユーザー バカらっく
提出日時 2021-11-10 10:04:36
言語 Kotlin
(2.3.20)
コンパイル:
kotlinc _filename_ -include-runtime -d main.jar
実行:
kotlin main.jar
結果
AC  
実行時間 203 ms / 5,000 ms
コード長 914 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 8,947 ms
コンパイル使用メモリ 469,168 KB
実行使用メモリ 53,360 KB
最終ジャッジ日時 2026-05-14 22:16:49
合計ジャッジ時間 17,020 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge3_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
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