結果

問題 No.2283 Prohibit Three Consecutive
ユーザー Alex WiceAlex Wice
提出日時 2023-04-28 22:43:58
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 231 ms / 2,000 ms
コード長 553 bytes
コンパイル時間 169 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 77,696 KB
最終ジャッジ日時 2024-04-29 00:08:20
合計ジャッジ時間 2,346 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
51,584 KB
testcase_01 AC 42 ms
52,096 KB
testcase_02 AC 42 ms
51,840 KB
testcase_03 AC 81 ms
74,496 KB
testcase_04 AC 97 ms
77,696 KB
testcase_05 AC 197 ms
77,440 KB
testcase_06 AC 198 ms
77,440 KB
testcase_07 AC 43 ms
51,840 KB
testcase_08 AC 62 ms
64,000 KB
testcase_09 AC 60 ms
64,256 KB
testcase_10 AC 62 ms
66,816 KB
testcase_11 AC 63 ms
66,048 KB
testcase_12 AC 197 ms
77,312 KB
testcase_13 AC 231 ms
77,440 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def solve(n, s):
    if n <= 2:
        return True
    s = list(s)
    for i in range(n):
        if s[i] == "?":
            if s[(i - 1) % n] == s[(i - 2) % n] != "?":
                s[i] = str(int(s[i - 1]) ^ 1)
    for i in range(n - 1, -1, -1):
        if s[i] == "?":
            if s[(i + 1) % n] == s[(i + 2) % n] != "?":
                s[i] = str(int(s[(i + 1) % n]) ^ 1)
    s = "".join(s)
    t = s + s
    return "111" not in t and "000" not in t
    
for tc in range(int(input())):
	print("Yes" if solve(int(input()), input()) else "No")
0