結果

問題 No.2283 Prohibit Three Consecutive
ユーザー lloyz
提出日時 2023-04-28 22:16:33
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 245 ms / 2,000 ms
コード長 771 bytes
コンパイル時間 187 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 80,000 KB
最終ジャッジ日時 2024-11-17 21:13:40
合計ジャッジ時間 2,459 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 13
権限があれば一括ダウンロードができます

ソースコード

diff #

for _ in range(int(input())):
    n = int(input())
    S = list(input())
    flag = True
    for _ in range(2):
        for i in range(n):
            C = [0, 0]
            q_idx = []
            for j in range(3):
                if S[(i + j) % n] == '0':
                    C[0] += 1
                elif S[(i + j) % n] == '1':
                    C[1] += 1
                else:
                    q_idx.append((i + j) % n)
            if C[0] == 3 or C[1] == 3:
                flag = False
                break
            if C[0] == 2 and C[1] == 0:
                S[q_idx[0]] = '1'
            if C[1] == 2 and C[0] == 0:
                S[q_idx[0]] = '0'
        if not flag:
            break
    if flag:
        print("Yes")
    else:
        print("No")
0