結果

問題 No.2283 Prohibit Three Consecutive
ユーザー mkawa2mkawa2
提出日時 2023-05-04 09:20:16
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 147 ms / 2,000 ms
コード長 1,336 bytes
コンパイル時間 891 ms
コンパイル使用メモリ 82,660 KB
実行使用メモリ 77,664 KB
最終ジャッジ日時 2024-05-01 21:08:42
合計ジャッジ時間 3,052 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
53,820 KB
testcase_01 AC 44 ms
59,304 KB
testcase_02 AC 41 ms
52,748 KB
testcase_03 AC 97 ms
77,664 KB
testcase_04 AC 96 ms
77,312 KB
testcase_05 AC 147 ms
76,612 KB
testcase_06 AC 143 ms
76,736 KB
testcase_07 AC 39 ms
52,552 KB
testcase_08 AC 69 ms
76,440 KB
testcase_09 AC 82 ms
76,920 KB
testcase_10 AC 75 ms
76,528 KB
testcase_11 AC 93 ms
76,772 KB
testcase_12 AC 111 ms
76,704 KB
testcase_13 AC 144 ms
76,884 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(200005)
# sys.set_int_max_str_digits(200005)
int1 = lambda x: int(x)-1
pDB = lambda *x: print(*x, end="\n", file=sys.stderr)
p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()

dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
inf = (1 << 63)-1
# md = 10**9+7
md = 998244353

def solve():
    n = II()
    cc = ["01?".find(c) for c in SI()]
    for s0 in range(4):
        dp = [0]*4
        dp[s0] = 1
        for c in cc:
            ndp = [0]*4
            for s in range(4):
                if dp[s] == 0: continue
                for d in range(2):
                    if d == 0 and s == 0: continue
                    if d == 1 and s == 3: continue
                    if d ^ c == 1: continue
                    ndp[s>>1|d<<1]=1
            dp=ndp
        if dp[s0]:
            print("Yes")
            return
    print("No")

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