結果

問題 No.2283 Prohibit Three Consecutive
ユーザー 👑 箱
提出日時 2023-02-13 11:09:03
言語 Kotlin
(1.9.23)
結果
RE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,135 bytes
コンパイル時間 15,129 ms
コンパイル使用メモリ 452,500 KB
実行使用メモリ 52,384 KB
最終ジャッジ日時 2024-04-24 20:53:40
合計ジャッジ時間 20,895 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 AC 304 ms
51,712 KB
testcase_09 AC 296 ms
51,784 KB
testcase_10 AC 297 ms
51,660 KB
testcase_11 WA -
testcase_12 RE -
testcase_13 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

fun PrintWriter.solve() {
    val n = nextInt()
    val s = nextLine()
    var t = s + s
    for (i in 0 until n - 1) {
        if (s[i] != '?' && s[i + 1] != '?') {
            val s0 = s.slice(i until n) + s.slice(0 until i)
            t = s0 + s0
            break
        }
    }
    if (s[0] != '?' && s[n - 1] != '?') {
        val s0 = s[n - 1] + s.slice(0 until n - 1)
        t = s0 + s0
    }
    val dp = Array(2 * n) { Array(2) { Array(2) { false } } }
    val x0 = if (t[0] == '0') arrayOf(0) else if (t[0] == '1') arrayOf(1) else arrayOf(0, 1)
    val x1 = if (t[1] == '0') arrayOf(0) else if (t[1] == '1') arrayOf(1) else arrayOf(0, 1)
    for (c0 in x0) {
        for (c1 in x1) {
            dp[1][c1][c0] = true
        }
    }
    for (i in 2 until 2 * n) {
        val x = if (t[i] == '0') arrayOf(0) else if (t[i] == '1') arrayOf(1) else arrayOf(0, 1)
        for (c0 in arrayOf(0, 1)) {
            for (c1 in arrayOf(0, 1)) {
                if (dp[i - 1][c1][c0]) {
                    for (c in x) {
                        if (c0 == c1 && c1 == c) {
                            continue
                        }
                        dp[i][c][c1] = true
                    }
                }
            }
        }
    }
    val b = dp[2 * n - 1][0][0] || dp[2 * n - 1][0][1] || dp[2 * n - 1][1][0] || dp[2 * n - 1][1][1]
    println(if (b) "Yes" else "No")
}

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