結果

問題 No.2283 Prohibit Three Consecutive
ユーザー ああいいああいい
提出日時 2023-04-29 08:58:43
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,402 bytes
コンパイル時間 591 ms
コンパイル使用メモリ 82,216 KB
実行使用メモリ 82,304 KB
最終ジャッジ日時 2024-04-29 06:36:59
合計ジャッジ時間 2,836 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
51,968 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 89 ms
80,256 KB
testcase_04 AC 94 ms
78,904 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 55 ms
81,800 KB
testcase_09 AC 62 ms
81,920 KB
testcase_10 AC 62 ms
82,304 KB
testcase_11 AC 65 ms
81,664 KB
testcase_12 WA -
testcase_13 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

T = int(input())

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 >> 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

for _ in range(T):
    N = int(input())
    S = input()
    
    print('Yes' if calc(N,S) else 'No')
0