結果

問題 No.1053 ゲーミング棒
ユーザー rutilicusrutilicus
提出日時 2020-10-16 09:25:05
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 496 ms / 2,000 ms
コード長 1,150 bytes
コンパイル時間 14,270 ms
コンパイル使用メモリ 415,868 KB
実行使用メモリ 64,088 KB
最終ジャッジ日時 2023-09-28 01:45:04
合計ジャッジ時間 30,983 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 286 ms
52,792 KB
testcase_01 AC 288 ms
52,932 KB
testcase_02 AC 289 ms
52,956 KB
testcase_03 AC 290 ms
53,012 KB
testcase_04 AC 288 ms
52,980 KB
testcase_05 AC 290 ms
52,652 KB
testcase_06 AC 288 ms
52,808 KB
testcase_07 AC 287 ms
53,140 KB
testcase_08 AC 289 ms
52,796 KB
testcase_09 AC 294 ms
53,084 KB
testcase_10 AC 286 ms
53,048 KB
testcase_11 AC 289 ms
52,756 KB
testcase_12 AC 291 ms
52,920 KB
testcase_13 AC 288 ms
52,884 KB
testcase_14 AC 284 ms
52,836 KB
testcase_15 AC 287 ms
52,956 KB
testcase_16 AC 290 ms
52,752 KB
testcase_17 AC 287 ms
52,904 KB
testcase_18 AC 295 ms
53,080 KB
testcase_19 AC 286 ms
52,964 KB
testcase_20 AC 287 ms
52,880 KB
testcase_21 AC 289 ms
52,848 KB
testcase_22 AC 287 ms
53,044 KB
testcase_23 AC 481 ms
63,780 KB
testcase_24 AC 496 ms
64,088 KB
testcase_25 AC 491 ms
63,804 KB
testcase_26 AC 489 ms
63,828 KB
testcase_27 AC 285 ms
52,992 KB
testcase_28 AC 287 ms
52,896 KB
testcase_29 AC 288 ms
52,868 KB
testcase_30 AC 446 ms
57,856 KB
testcase_31 AC 458 ms
57,812 KB
testcase_32 AC 458 ms
57,736 KB
testcase_33 AC 457 ms
57,816 KB
testcase_34 AC 453 ms
57,948 KB
testcase_35 AC 459 ms
57,660 KB
testcase_36 AC 457 ms
57,684 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

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

    builder.appendln(ans)

    print(builder.toString())
}

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