結果

問題 No.204 ゴールデン・ウィーク(2)
ユーザー rutilicusrutilicus
提出日時 2020-10-16 01:26:22
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 312 ms / 1,000 ms
コード長 1,642 bytes
コンパイル時間 15,484 ms
コンパイル使用メモリ 421,712 KB
実行使用メモリ 54,976 KB
最終ジャッジ日時 2023-09-28 01:38:35
合計ジャッジ時間 33,018 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 306 ms
53,080 KB
testcase_01 AC 304 ms
52,828 KB
testcase_02 AC 309 ms
52,884 KB
testcase_03 AC 307 ms
54,908 KB
testcase_04 AC 308 ms
52,828 KB
testcase_05 AC 312 ms
52,860 KB
testcase_06 AC 306 ms
53,124 KB
testcase_07 AC 306 ms
52,860 KB
testcase_08 AC 310 ms
52,880 KB
testcase_09 AC 306 ms
52,672 KB
testcase_10 AC 305 ms
52,860 KB
testcase_11 AC 306 ms
53,092 KB
testcase_12 AC 309 ms
52,888 KB
testcase_13 AC 308 ms
53,124 KB
testcase_14 AC 311 ms
52,980 KB
testcase_15 AC 306 ms
52,676 KB
testcase_16 AC 307 ms
52,956 KB
testcase_17 AC 303 ms
52,820 KB
testcase_18 AC 306 ms
52,956 KB
testcase_19 AC 305 ms
53,168 KB
testcase_20 AC 304 ms
53,012 KB
testcase_21 AC 308 ms
52,972 KB
testcase_22 AC 304 ms
52,880 KB
testcase_23 AC 308 ms
52,872 KB
testcase_24 AC 309 ms
53,056 KB
testcase_25 AC 307 ms
52,824 KB
testcase_26 AC 302 ms
52,984 KB
testcase_27 AC 306 ms
52,848 KB
testcase_28 AC 301 ms
54,976 KB
testcase_29 AC 307 ms
52,880 KB
testcase_30 AC 304 ms
53,120 KB
testcase_31 AC 308 ms
52,984 KB
testcase_32 AC 296 ms
53,156 KB
testcase_33 AC 303 ms
52,888 KB
testcase_34 AC 304 ms
52,884 KB
testcase_35 AC 306 ms
52,852 KB
testcase_36 AC 307 ms
53,028 KB
testcase_37 AC 306 ms
52,800 KB
testcase_38 AC 302 ms
52,896 KB
testcase_39 AC 303 ms
52,868 KB
testcase_40 AC 302 ms
52,876 KB
testcase_41 AC 312 ms
53,052 KB
testcase_42 AC 302 ms
53,088 KB
testcase_43 AC 307 ms
52,976 KB
testcase_44 AC 308 ms
52,884 KB
testcase_45 AC 307 ms
53,004 KB
testcase_46 AC 307 ms
52,672 KB
testcase_47 AC 306 ms
52,892 KB
testcase_48 AC 300 ms
53,116 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:42: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(max(d, ans))
            ^

ソースコード

diff #

import kotlin.math.max

fun main() {
    val builder = StringBuilder()

    val d = readInputLine().toInt()

    val c = readInputLine() + readInputLine()

    val runLength = runLength(c).toMutableList()

    if (runLength[0].first == 'x') {
        runLength[0] = runLength[0].copy(second = 15)
    } else {
        runLength.add(0, Pair('x', 15))
    }

    if (runLength[runLength.lastIndex].first == 'x') {
        runLength[runLength.lastIndex] = runLength[runLength.lastIndex].copy(second = 15)
    } else {
        runLength.add(Pair('x', 15))
    }

    var ans = 0

    val arr = runLength.toTypedArray()

    for ((i, p) in arr.withIndex()) {
        if (p.first != 'o') {
            continue
        }

        ans = max(ans, when(arr[i - 1].second - d) {
            in Int.MIN_VALUE..0 -> p.second + arr[i - 1].second + arr[i - 2].second
            else -> p.second + d } )

        ans = max(ans, when(arr[i + 1].second - d) {
            in Int.MIN_VALUE..0 -> p.second + arr[i + 1].second + arr[i + 2].second
            else -> p.second + d } )
    }

    builder.appendln(max(d, ans))

    print(builder.toString())
}

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

fun runLength(s: String): List<Pair<Char, Int>> {
    val ret = mutableListOf<Pair<Char, Int>>()

    if (s.isNotEmpty()) {
        var prev = s[0]
        var cnt = 0

        for (c in s) {
            if (c == prev) {
                cnt++
            } else {
                ret.add(Pair(prev, cnt))
                prev = c
                cnt = 1
            }
        }

        ret.add(Pair(prev, cnt))
    }

    return ret.toList()
}
0