結果

問題 No.2283 Prohibit Three Consecutive
ユーザー ntudantuda
提出日時 2023-04-29 11:26:26
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 773 bytes
コンパイル時間 173 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 77,696 KB
最終ジャッジ日時 2024-04-29 07:44:16
合計ジャッジ時間 2,243 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
51,968 KB
testcase_01 AC 43 ms
51,584 KB
testcase_02 AC 40 ms
52,096 KB
testcase_03 AC 51 ms
62,976 KB
testcase_04 AC 55 ms
68,608 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 64 ms
66,304 KB
testcase_09 AC 66 ms
66,560 KB
testcase_10 AC 70 ms
67,712 KB
testcase_11 AC 61 ms
64,640 KB
testcase_12 WA -
testcase_13 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

T = int(input())


def repl(s):
    if s == "0":
        return "1"
    else:
        return "0"


def solve():
    N = int(input())
    S = list(input())
    for i in range(N):
        if S[(i - 2) % N] == S[(i - 1) % N] == S[i] != "?":
            print("No")
            #print(S)
            return
        if S[i] == "?":
            if S[(i - 2) % N] == S[(i - 1) % N] != "?":
                S[i] = repl(S[(i - 1) % N])
    for i in reversed(range(N)):
        if S[(i + 2) % N] == S[(i + 1) % N] == S[i] != "?":
            print("No")
            #print(S)
            return
        if S[i] == "?":
            if S[(i + 2) % N] == S[(i + 1) % N] != "?":
                S[i] = repl(S[(i + 1) % N])
    print("Yes")
    #print(S)


for _ in range(T):
    solve()
0