結果

問題 No.2283 Prohibit Three Consecutive
ユーザー buey_tbuey_t
提出日時 2023-04-29 11:54:24
言語 PyPy3
(7.3.13)
結果
WA  
実行時間 -
コード長 4,444 bytes
コンパイル時間 950 ms
コンパイル使用メモリ 86,844 KB
実行使用メモリ 205,728 KB
最終ジャッジ日時 2023-08-11 15:58:39
合計ジャッジ時間 9,199 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 230 ms
83,160 KB
testcase_01 AC 231 ms
82,848 KB
testcase_02 WA -
testcase_03 AC 862 ms
205,728 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 502 ms
145,640 KB
testcase_09 AC 504 ms
146,580 KB
testcase_10 AC 541 ms
146,712 KB
testcase_11 AC 540 ms
146,592 KB
testcase_12 WA -
testcase_13 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import sqrt,sin,cos,tan,ceil,radians,floor,gcd,exp,log,log10,log2,factorial,fsum
from heapq import heapify, heappop, heappush
from bisect import bisect_left, bisect_right
from copy import deepcopy
import copy
import random
from random import randrange
from collections import deque,Counter,defaultdict
from itertools import permutations,combinations
from decimal import Decimal,ROUND_HALF_UP
#tmp = Decimal(mid).quantize(Decimal('0'), rounding=ROUND_HALF_UP)
from functools import lru_cache, reduce
#@lru_cache(maxsize=None)
from operator import add,sub,mul,xor,and_,or_,itemgetter
import sys
input = sys.stdin.readline
# .rstrip()
INF = 10**18
mod1 = 10**9+7
mod2 = 998244353

#DecimalならPython
#再帰ならPython!!!!!!!!!!!!!!!!!!!!!!!!!!

def calc(N,S):
    t = []
    for s in S:
        if s == "?":
            t.append(2)
        else:
            t.append(int(s))

    for init in range(4):
        flag = True
        for i in range(2):
            if t[i] == 2 or t[i] == ((init >> (1 - i)) & 1):
                pass
            else:
                flag = False
        if flag == False:
            continue
        dat = [0] * 4
        dat[init] = 1
        for j in range(2,N):
            nx = [0] * 4
            if t[j] == 2 or t[j] == 1:
                for bit in range(3):
                    nx [((bit << 1) | 1) & 3] |= dat[bit]
            if t[j] == 2 or t[j] == 0:
                for bit in range(1,4):
                    nx [(bit << 1) & 3] |= dat[bit]
            dat = nx
        for bit in range(4):
            if dat[bit]:
                flag = True
                tmp = (bit << 1) | (init >> 1)
                if tmp == 0 or tmp == 7:
                    flag = False
                else:
                    pass
                tmp = ((bit & 1) << 2) | init
                if tmp == 0 or tmp == 7:
                    flag = False
                else:
                    pass
                if flag:
                    #print(bit,tmp,init)
                    return True
    return False

'''
dpだとは思う
直前の二個を記録すればいいかな
1周回ってきたときに、最初の?をなにで解釈したか考えないといけない
最初の?が1じゃないとダメなとき、11が後ろにあったらダメ
3文字メモしておかないとだめ?
'''

for _ in range(int(input())):
    N = int(input())
    S = list(input().rstrip())
    
    dp = [[[[0]*2 for _ in range(2)] for _ in range(2)] for _ in range(N+1)]
    
    for i in range(2):
        for j in range(2):
            for k in range(2):
                dp[0][i][j][k] = 1
    
    for i in range(1,N+1):
        if S[i-1] == '0':
            for j in range(2):
                for k in range(2):
                    for l in range(2):
                        if j == k == 0:
                            continue
                        dp[i][j][k][0] = max(dp[i][j][k][0], dp[i-1][l][j][k])
        elif S[i-1] == '1':
            for j in range(2):
                for k in range(2):
                    for l in range(2):
                        if j == k == 1:
                            continue
                        dp[i][j][k][1] = max(dp[i][j][k][1], dp[i-1][l][j][k])
        else:
            for j in range(2):
                for k in range(2):
                    for l in range(2):
                        if j == k == 0:
                            continue
                        dp[i][j][k][0] = max(dp[i][j][k][0], dp[i-1][l][j][k])
            for j in range(2):
                for k in range(2):
                    for l in range(2):
                        if j == k == 1:
                            continue
                        dp[i][j][k][1] = max(dp[i][j][k][1], dp[i-1][l][j][k])
    
    f = 0
    for i in range(2):
        for j in range(2):
            for k in range(2):
                if dp[N][i][j][k] == 1:
                    if j == k:
                        for l in range(2):
                            for m in range(2):
                                if dp[3][(j+1)%2][l][m] == 1:
                                    f = 1
                    else:
                        for l in range(2):
                            for m in range(2):
                                if dp[3][m][(m+1)%2][l] == 1:
                                    f = 1
    
    if f:
        print('Yes')
    else:
        print('No')

























0