結果

問題 No.2283 Prohibit Three Consecutive
ユーザー ShirotsumeShirotsume
提出日時 2023-04-28 23:05:22
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,148 bytes
コンパイル時間 152 ms
コンパイル使用メモリ 82,392 KB
実行使用メモリ 126,496 KB
最終ジャッジ日時 2024-04-29 00:21:54
合計ジャッジ時間 2,842 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
55,040 KB
testcase_01 AC 48 ms
55,552 KB
testcase_02 AC 46 ms
55,808 KB
testcase_03 AC 142 ms
122,752 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 48 ms
55,680 KB
testcase_08 AC 78 ms
85,360 KB
testcase_09 AC 108 ms
123,648 KB
testcase_10 WA -
testcase_11 AC 118 ms
125,440 KB
testcase_12 AC 229 ms
78,808 KB
testcase_13 AC 271 ms
79,776 KB
権限があれば一括ダウンロードができます

ソースコード

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()
    s = [-1 if v == '?' else int(v) for v in input()]
    x = random.randint(0, n)
    s = s[x:] + s[:x]
    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 and a[i - 2] == 1):
                a[i] = 0
            elif a[i] == -1:
                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