結果

問題 No.1053 ゲーミング棒
ユーザー rutilicusrutilicus
提出日時 2020-10-16 09:27:19
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 463 ms / 2,000 ms
コード長 1,169 bytes
コンパイル時間 12,810 ms
コンパイル使用メモリ 421,240 KB
実行使用メモリ 64,500 KB
最終ジャッジ日時 2023-09-28 01:45:32
合計ジャッジ時間 26,859 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 267 ms
53,348 KB
testcase_01 AC 268 ms
52,840 KB
testcase_02 AC 268 ms
52,780 KB
testcase_03 AC 269 ms
52,768 KB
testcase_04 AC 266 ms
52,816 KB
testcase_05 AC 270 ms
53,000 KB
testcase_06 AC 267 ms
53,108 KB
testcase_07 AC 270 ms
53,124 KB
testcase_08 AC 273 ms
52,844 KB
testcase_09 AC 272 ms
53,148 KB
testcase_10 AC 276 ms
52,836 KB
testcase_11 AC 273 ms
52,804 KB
testcase_12 AC 289 ms
53,228 KB
testcase_13 AC 268 ms
52,896 KB
testcase_14 AC 268 ms
53,024 KB
testcase_15 AC 270 ms
52,916 KB
testcase_16 AC 271 ms
53,148 KB
testcase_17 AC 269 ms
52,868 KB
testcase_18 AC 270 ms
52,784 KB
testcase_19 AC 269 ms
52,728 KB
testcase_20 AC 267 ms
52,896 KB
testcase_21 AC 266 ms
53,052 KB
testcase_22 AC 278 ms
53,288 KB
testcase_23 AC 463 ms
64,500 KB
testcase_24 AC 456 ms
64,016 KB
testcase_25 AC 461 ms
64,008 KB
testcase_26 AC 458 ms
64,012 KB
testcase_27 AC 270 ms
52,684 KB
testcase_28 AC 260 ms
52,956 KB
testcase_29 AC 269 ms
52,884 KB
testcase_30 AC 423 ms
58,012 KB
testcase_31 AC 420 ms
57,980 KB
testcase_32 AC 430 ms
57,692 KB
testcase_33 AC 426 ms
57,724 KB
testcase_34 AC 429 ms
57,644 KB
testcase_35 AC 430 ms
58,076 KB
testcase_36 AC 434 ms
57,812 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:49:13: warning: 'appendln(Int): kotlin.text.StringBuilder /* = java.lang.StringBuilder */' is deprecated. Use appendLine instead. Note that the new method always appends the line feed character '\n' regardless of the system line separator.
    builder.appendln(ans)
            ^

ソースコード

diff #

fun main() {
    val builder = StringBuilder()

    // 解説読んだ
    // 問題のシチュは環とみなせるっぽい
    // 異なる数字がある場合、左右端がその数字の場合のみ1回移動で連続とみなせる

    val n = readInputLine().toInt()

    val list = mutableListOf<Int>()

    var prev = -1

    readInputLine().split(" ").map {
        (it.toInt() - 1).apply {
            if (this != prev) {
                if (prev != -1) {
                    list.add(prev)
                }
                prev = this
            }
        }
    }

    list.add(prev)

    val cnt = IntArray(n)

    var ans = 0

    check@ for (l in list) {
        when(cnt[l]) {
            0 -> cnt[l]++
            1 -> {
                if (list.first() != l || list.last() != l) {
                    ans = -1
                    break@check
                }
                cnt[l]++
                ans = 1
            }
            else -> {
                ans = -1
                break@check
            }
        }
    }

    builder.appendln(ans)

    print(builder.toString())
}

fun readInputLine(): String {
    return readLine()!!
}
0