結果

問題 No.2283 Prohibit Three Consecutive
ユーザー ShirotsumeShirotsume
提出日時 2023-04-28 23:01:50
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,072 bytes
コンパイル時間 158 ms
コンパイル使用メモリ 82,008 KB
実行使用メモリ 140,696 KB
最終ジャッジ日時 2024-04-29 00:20:22
合計ジャッジ時間 2,363 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
55,664 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 42 ms
54,932 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 96 ms
119,500 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

def solve():
    n = ii()
    s = [-1 if v == '?' else int(v) for v in input()]
    p = []
    for i in range(n):
        if s[i] == -1:
            p.append(i)
    p = list(set(p[:3] + p[-3:]))

    m = len(p)

    for bit in range(1 << m):
        a = s[::]
        for i in range(m):
            if 1 & (bit >> i):
                a[p[i]] = 1
            else:
                a[p[i]] = 0
        f = False
        for i in range(2, n):
            if a[i] == -1 and (a[i - 1] == 1 or a[i - 2] == 1):
                a[i] = 0
            else:
                a[i] = 1
            if a[i-2] == a[i-1] == a[i]:
                f = True
                break 
        if f or a[-1] == a[0] == a[1] or a[-2] == a[-1] == a[0]:
            pass
        else:
            print('Yes')
            return
    print('No')


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