結果

問題 No.887 Collatz
ユーザー バカらっくバカらっく
提出日時 2022-02-03 14:19:53
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 273 ms / 2,000 ms
コード長 355 bytes
コンパイル時間 11,906 ms
コンパイル使用メモリ 426,328 KB
実行使用メモリ 52,940 KB
最終ジャッジ日時 2023-09-02 03:17:40
合計ジャッジ時間 22,151 ms
ジャッジサーバーID
(参考情報)
judge16 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 257 ms
52,928 KB
testcase_01 AC 266 ms
52,652 KB
testcase_02 AC 260 ms
52,940 KB
testcase_03 AC 272 ms
52,396 KB
testcase_04 AC 261 ms
52,668 KB
testcase_05 AC 269 ms
52,688 KB
testcase_06 AC 268 ms
52,560 KB
testcase_07 AC 261 ms
52,772 KB
testcase_08 AC 260 ms
52,680 KB
testcase_09 AC 265 ms
52,652 KB
testcase_10 AC 263 ms
52,540 KB
testcase_11 AC 258 ms
52,428 KB
testcase_12 AC 262 ms
52,504 KB
testcase_13 AC 266 ms
52,804 KB
testcase_14 AC 255 ms
52,496 KB
testcase_15 AC 261 ms
52,588 KB
testcase_16 AC 269 ms
52,672 KB
testcase_17 AC 273 ms
52,856 KB
testcase_18 AC 267 ms
52,452 KB
testcase_19 AC 263 ms
52,456 KB
testcase_20 AC 269 ms
52,676 KB
testcase_21 AC 266 ms
52,636 KB
testcase_22 AC 266 ms
52,448 KB
testcase_23 AC 263 ms
52,652 KB
testcase_24 AC 266 ms
52,672 KB
testcase_25 AC 266 ms
52,576 KB
testcase_26 AC 261 ms
52,700 KB
testcase_27 AC 266 ms
52,740 KB
testcase_28 AC 261 ms
52,564 KB
testcase_29 AC 269 ms
52,612 KB
testcase_30 AC 269 ms
52,704 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:3:10: warning: parameter 'args' is never used
fun main(args: Array<String>) {
         ^

ソースコード

diff #

import java.util.*

fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val arr = Stack<Int>().also { it.push(n) }
    while (arr.peek() != 1) {
        if(arr.peek() % 2 == 0) {
            arr.push(arr.peek()/2)
        } else {
            arr.push(arr.peek()*3+1)
        }
    }
    println(arr.size-1)
    println(arr.maxOrNull())
}
0