結果
問題 |
No.45 回転寿司
|
ユーザー |
![]() |
提出日時 | 2021-11-10 10:04:36 |
言語 | Kotlin (2.1.0) |
結果 |
AC
|
実行時間 | 380 ms / 5,000 ms |
コード長 | 914 bytes |
コンパイル時間 | 12,329 ms |
コンパイル使用メモリ | 445,708 KB |
実行使用メモリ | 52,212 KB |
最終ジャッジ日時 | 2024-11-20 18:51:32 |
合計ジャッジ時間 | 25,263 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 30 |
コンパイルメッセージ
Main.kt:3:10: warning: parameter 'args' is never used fun main(args: Array<String>) { ^
ソースコード
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]!!) }