結果

問題 No.2283 Prohibit Three Consecutive
ユーザー ああいいああいい
提出日時 2023-04-29 09:07:30
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 250 ms / 2,000 ms
コード長 1,416 bytes
コンパイル時間 211 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 81,664 KB
最終ジャッジ日時 2024-04-29 06:42:25
合計ジャッジ時間 2,586 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
52,096 KB
testcase_01 AC 40 ms
52,608 KB
testcase_02 AC 40 ms
52,352 KB
testcase_03 AC 105 ms
79,796 KB
testcase_04 AC 126 ms
79,080 KB
testcase_05 AC 220 ms
77,312 KB
testcase_06 AC 225 ms
77,312 KB
testcase_07 AC 39 ms
52,736 KB
testcase_08 AC 66 ms
81,536 KB
testcase_09 AC 84 ms
81,664 KB
testcase_10 AC 73 ms
81,496 KB
testcase_11 AC 89 ms
81,664 KB
testcase_12 AC 208 ms
77,896 KB
testcase_13 AC 250 ms
77,732 KB
権限があれば一括ダウンロードができます

ソースコード

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

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