結果

問題 No.2283 Prohibit Three Consecutive
ユーザー ShirotsumeShirotsume
提出日時 2023-04-28 23:14:34
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,550 bytes
コンパイル時間 237 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 125,312 KB
最終ジャッジ日時 2024-04-29 00:27:52
合計ジャッジ時間 3,690 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
55,552 KB
testcase_01 AC 44 ms
56,064 KB
testcase_02 AC 44 ms
56,192 KB
testcase_03 AC 259 ms
125,312 KB
testcase_04 AC 253 ms
119,424 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 150 ms
102,564 KB
testcase_09 AC 156 ms
102,768 KB
testcase_10 AC 154 ms
102,656 KB
testcase_11 AC 155 ms
102,528 KB
testcase_12 WA -
testcase_13 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from collections import deque, Counter
input = lambda: sys.stdin.readline().rstrip()
ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(mi())
inf = 2 ** 63 - 1
mod = 998244353
import random
def solve():
    n = ii()
    a = [-1 if v == '?' else int(v) for v in input()]
    dp = [[[0] * 2 for _ in range(2)] for _ in range(n + 1)]

    if a[0] == a[1] == -1:
        dp[2][0][0] = 1
        dp[2][0][1] = 1
        dp[2][1][0] = 1
        dp[2][1][1] = 1
    elif a[0] == -1:
        dp[2][0][a[1]] = 1
        dp[2][1][a[1]] = 1
    elif a[1] == -1:
        dp[2][a[0]][0] = 1
        dp[2][a[0]][1] = 1
    else:
        dp[2][a[0]][a[1]] = 1

    for i in range(2, n):
        for j in range(2):
            for k in range(2):
                if a[i] == -1:
                    if j == k:
                        dp[i + 1][k][1 - k] |= dp[i][j][k]
                    else:
                        dp[i + 1][k][0] |= dp[i][j][k]
                        dp[i + 1][k][1] |= dp[i][j][k]
                else:
                    if j == k == a[i]:
                        pass
                    else:
                        dp[i + 1][k][a[i]] |= dp[i][j][k]
    
    for a1 in range(2):
        for a2 in range(2):
            for b1 in range(2):
                for b2 in range(2):
                    if not((a1 == a2 == b2) or (a1 == b1 == b2)) and dp[2][a1][a2] and dp[n][b1][b2]:
                        print('Yes')
                        return
    print('No')


for _ in range(ii()):
    solve()
0