結果

問題 No.204 ゴールデン・ウィーク(2)
ユーザー rutilicusrutilicus
提出日時 2020-10-16 01:18:33
言語 Kotlin
(1.9.23)
結果
WA  
実行時間 -
コード長 1,756 bytes
コンパイル時間 15,871 ms
コンパイル使用メモリ 423,872 KB
実行使用メモリ 54,980 KB
最終ジャッジ日時 2023-09-28 01:36:45
合計ジャッジ時間 32,360 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 266 ms
52,860 KB
testcase_02 AC 268 ms
52,888 KB
testcase_03 AC 273 ms
52,852 KB
testcase_04 AC 272 ms
52,816 KB
testcase_05 AC 268 ms
52,868 KB
testcase_06 AC 266 ms
52,912 KB
testcase_07 AC 266 ms
52,884 KB
testcase_08 AC 267 ms
52,788 KB
testcase_09 AC 260 ms
52,856 KB
testcase_10 AC 263 ms
53,092 KB
testcase_11 AC 266 ms
52,992 KB
testcase_12 AC 268 ms
52,932 KB
testcase_13 AC 270 ms
52,748 KB
testcase_14 AC 268 ms
53,040 KB
testcase_15 AC 267 ms
52,928 KB
testcase_16 AC 267 ms
52,868 KB
testcase_17 AC 265 ms
52,844 KB
testcase_18 AC 263 ms
52,808 KB
testcase_19 AC 269 ms
52,816 KB
testcase_20 AC 265 ms
52,852 KB
testcase_21 AC 263 ms
52,852 KB
testcase_22 AC 268 ms
52,812 KB
testcase_23 AC 263 ms
53,232 KB
testcase_24 AC 273 ms
52,884 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 272 ms
52,892 KB
testcase_29 AC 272 ms
53,004 KB
testcase_30 AC 271 ms
52,876 KB
testcase_31 WA -
testcase_32 AC 269 ms
53,064 KB
testcase_33 AC 272 ms
52,964 KB
testcase_34 AC 263 ms
52,820 KB
testcase_35 AC 271 ms
52,936 KB
testcase_36 AC 269 ms
52,860 KB
testcase_37 AC 267 ms
52,856 KB
testcase_38 AC 264 ms
52,868 KB
testcase_39 AC 267 ms
52,720 KB
testcase_40 AC 275 ms
52,844 KB
testcase_41 WA -
testcase_42 AC 266 ms
53,028 KB
testcase_43 AC 269 ms
52,984 KB
testcase_44 AC 269 ms
52,944 KB
testcase_45 AC 267 ms
52,824 KB
testcase_46 AC 266 ms
53,008 KB
testcase_47 AC 270 ms
52,816 KB
testcase_48 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:50: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 #

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
        }

        if (arr[i - 1].second >= d) {
            if (arr[i - 1].second == d) {
                ans = max(ans, p.second + d + arr[i - 2].second)
            } else {
                ans = max(ans, p.second + d)
            }
        }

        if (arr[i + 1].second >= d) {
            if (arr[i + 1].second == d) {
                ans = max(ans, p.second + d + arr[i + 2].second)
            } else {
                ans = max(ans, p.second + d)
            }
        }
    }

    builder.appendln(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