結果

問題 No.154 市バス
ユーザー rutilicusrutilicus
提出日時 2020-12-17 19:05:07
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 671 ms / 2,000 ms
コード長 1,420 bytes
コンパイル時間 13,566 ms
コンパイル使用メモリ 440,420 KB
実行使用メモリ 61,872 KB
最終ジャッジ日時 2023-10-21 07:04:46
合計ジャッジ時間 18,604 ms
ジャッジサーバーID
(参考情報)
judge9 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 598 ms
60,800 KB
testcase_01 AC 603 ms
60,784 KB
testcase_02 AC 597 ms
60,796 KB
testcase_03 AC 671 ms
61,872 KB
testcase_04 AC 646 ms
60,832 KB
testcase_05 AC 323 ms
54,176 KB
testcase_06 AC 312 ms
54,180 KB
testcase_07 AC 561 ms
60,736 KB
testcase_08 AC 318 ms
54,184 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Main.kt:56:17: warning: 'appendln(String?): 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(if (ok) "possible" else "impossible")
                ^

ソースコード

diff #

fun main() {
    val builder = StringBuilder()

    val t = readInputLine().toInt()

    repeat(t) {
        val input = readInputLine()
        var ok = true
        var rCnt = 0
        var gCnt = 0
        var wCnt = 0

        input.forEach {
            when(it) {
                'G' -> {
                    gCnt++
                    if (gCnt > wCnt) {
                        ok = false
                    }
                }
                'R' -> {
                    rCnt++
                    if (rCnt > wCnt || rCnt > gCnt) {
                        ok = false
                    }
                }
                else -> {
                    wCnt++
                }
            }
        }

        gCnt = 0
        rCnt = 0
        wCnt = 0

        input.reversed().forEach {
            when(it) {
                'G' -> {
                    gCnt++
                    if (gCnt > rCnt) {
                        ok = false
                    }
                }
                'R' -> {
                    rCnt++
                }
                else -> {
                    wCnt++
                    if (gCnt == 0 || wCnt == 0) {
                        ok = false
                    }
                }
            }
        }
        builder.appendln(if (ok) "possible" else "impossible")
    }

    print(builder.toString())
}

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