結果

問題 No.2042 RGB Caps
ユーザー 👑 箱星箱星
提出日時 2022-04-24 23:04:17
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 567 ms / 2,000 ms
コード長 820 bytes
コンパイル時間 12,656 ms
コンパイル使用メモリ 441,496 KB
実行使用メモリ 85,952 KB
最終ジャッジ日時 2024-04-27 20:29:31
合計ジャッジ時間 21,206 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 284 ms
60,112 KB
testcase_01 AC 289 ms
60,424 KB
testcase_02 AC 282 ms
60,388 KB
testcase_03 AC 282 ms
60,384 KB
testcase_04 AC 286 ms
60,100 KB
testcase_05 AC 279 ms
60,232 KB
testcase_06 AC 369 ms
65,248 KB
testcase_07 AC 489 ms
70,904 KB
testcase_08 AC 517 ms
81,344 KB
testcase_09 AC 434 ms
66,840 KB
testcase_10 AC 567 ms
85,952 KB
testcase_11 AC 443 ms
64,368 KB
testcase_12 AC 532 ms
81,848 KB
testcase_13 AC 530 ms
81,976 KB
testcase_14 AC 534 ms
82,040 KB
testcase_15 AC 298 ms
60,460 KB
testcase_16 AC 474 ms
70,816 KB
testcase_17 AC 442 ms
64,368 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

fun main() {
    val (n, k) = readInts()
    val arr = CharArray(n) { 'R' }
    for (i in 0 until k) {
        val data = readln().split(" ")
        val a = data[0].toInt()
        val c = data[1][0]
        arr[a - 1] = c
    }
    val ans = CharArray(n) { '.' }
    for (i in 0 until n) {
        val c = arr[i]
        if (i % 3 == 0) {
            ans[i] = c
        } else if (i % 3 == 1) {
            if (ans[i - 1] == c) {
                ans[i] = if (c == 'R') 'G' else 'R'
            } else {
                ans[i] = c
            }
        } else {
            val lst = mutableListOf('R', 'G', 'B')
            lst.remove(ans[i - 1])
            lst.remove(ans[i - 2])
            ans[i] = lst[0]
        }
    }
    println(ans.joinToString(""))
}

fun readInts() = readln().split(" ").map { it.toInt() }
0