結果

問題 No.2283 Prohibit Three Consecutive
ユーザー ntudantuda
提出日時 2023-04-29 11:42:40
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 249 ms / 2,000 ms
コード長 922 bytes
コンパイル時間 171 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 78,048 KB
最終ジャッジ日時 2024-04-29 07:52:28
合計ジャッジ時間 2,308 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
52,096 KB
testcase_01 AC 41 ms
52,224 KB
testcase_02 AC 42 ms
52,096 KB
testcase_03 AC 51 ms
62,592 KB
testcase_04 AC 57 ms
68,608 KB
testcase_05 AC 215 ms
77,184 KB
testcase_06 AC 219 ms
78,048 KB
testcase_07 AC 41 ms
51,712 KB
testcase_08 AC 72 ms
66,816 KB
testcase_09 AC 71 ms
67,200 KB
testcase_10 AC 76 ms
68,864 KB
testcase_11 AC 61 ms
64,640 KB
testcase_12 AC 213 ms
77,184 KB
testcase_13 AC 249 ms
77,312 KB
権限があれば一括ダウンロードができます

ソースコード

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])
    for i in range(N):
        if S[(i - 2) % N] == S[(i - 1) % N] == S[i] != "?":
            print("No")
            #print(S)
            return

    print("Yes")
    #print(S)


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