結果

問題 No.2042 RGB Caps
ユーザー 👑 箱
提出日時 2022-02-23 20:11:45
言語 Kotlin
(1.9.23)
結果
AC  
実行時間 616 ms / 2,000 ms
コード長 1,799 bytes
コンパイル時間 14,845 ms
コンパイル使用メモリ 442,508 KB
実行使用メモリ 94,648 KB
最終ジャッジ日時 2024-04-27 20:29:01
合計ジャッジ時間 19,527 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 282 ms
62,012 KB
testcase_01 AC 261 ms
62,084 KB
testcase_02 AC 255 ms
61,884 KB
testcase_03 AC 270 ms
62,132 KB
testcase_04 AC 274 ms
62,024 KB
testcase_05 AC 268 ms
62,244 KB
testcase_06 AC 340 ms
68,656 KB
testcase_07 AC 466 ms
75,624 KB
testcase_08 AC 517 ms
84,336 KB
testcase_09 AC 405 ms
69,332 KB
testcase_10 AC 574 ms
93,264 KB
testcase_11 AC 410 ms
67,400 KB
testcase_12 AC 580 ms
94,492 KB
testcase_13 AC 584 ms
94,352 KB
testcase_14 AC 616 ms
94,648 KB
testcase_15 AC 273 ms
62,052 KB
testcase_16 AC 450 ms
73,696 KB
testcase_17 AC 408 ms
67,396 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.PrintWriter
import java.util.*
import kotlin.math.*

fun PrintWriter.solve() {
    val n = nextInt()
    val k = nextInt()
    val map = mutableMapOf<Int, Char>()
    for (i in 0 until k) {
        val a = nextInt()
        val c = next()
        map[a - 1] = c[0]
    }
    val ans = CharArray(n) { '.' }
    for (i in 0 until n) {
        if (i % 3 == 0) {
            if (map.containsKey(i)) {
                val c = map[i]!!
                ans[i] = c
            } else {
                ans[i] = 'R'
            }
        } else if (i % 3 == 1) {
            if (map.containsKey((i))) {
                val c = map[i]!!
                if (ans[i - 1] == c) {
                    ans[i] = if (c == 'R') 'G' else 'R'
                } else {
                    ans[i] = c
                }
            } else {
                ans[i] = if (ans[i - 1] == 'R') 'G' else 'R'
            }
        } 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 main() {
    Thread(null, {
        val writer = PrintWriter(System.out, false)
        writer.solve()
        writer.flush()
    }, "solve", abs(1L.shl(26)))
        .apply { setUncaughtExceptionHandler { _, e -> e.printStackTrace(); kotlin.system.exitProcess(1) } }
        .apply { start() }.join()
}

// region Scanner
private var st = StringTokenizer("")
private val br = System.`in`.bufferedReader()

fun next(): String {
    while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())
    return st.nextToken()
}

fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextLine() = br.readLine()
fun nextDouble() = next().toDouble()
// endregion
0