結果

問題 No.2283 Prohibit Three Consecutive
ユーザー ああいいああいい
提出日時 2023-04-29 09:02:40
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,410 bytes
コンパイル時間 194 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 81,792 KB
最終ジャッジ日時 2024-04-29 06:39:41
合計ジャッジ時間 2,555 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 117 ms
80,128 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 76 ms
81,792 KB
testcase_09 AC 75 ms
81,792 KB
testcase_10 AC 82 ms
81,536 KB
testcase_11 AC 79 ms
81,792 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 & 2) << 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