結果

問題 No.2283 Prohibit Three Consecutive
コンテスト
ユーザー detteiuu
提出日時 2026-08-03 22:31:05
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 168 ms / 2,000 ms
+ 241µs
コード長 561 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 237 ms
コンパイル使用メモリ 95,732 KB
実行使用メモリ 85,120 KB
最終ジャッジ日時 2026-08-03 22:31:12
合計ジャッジ時間 3,233 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 13
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from sys import stdin
input = stdin.readline

for _ in range(int(input())):
    N = int(input())
    S = input().rstrip("\n")

    S *= 5
    dp = [False]*(1<<3)
    dp[0] = True
    for i in range(N*5):
        ndp = [False]*(1<<3)
        for bit in range(1<<3):
            if not dp[bit]: continue
            for j in range(2):
                if S[i] == "?" or int(S[i]) == j:
                    ndp[(bit<<1)%(1<<3)+j] = True
        if 2 <= i:
            ndp[0], ndp[(1<<3)-1] = False, False
        dp = ndp

    print("Yes" if 1 <= sum(dp) else "No")
0