結果

問題 No.2283 Prohibit Three Consecutive
ユーザー FromBooskaFromBooska
提出日時 2023-08-09 13:40:58
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 168 ms / 2,000 ms
コード長 932 bytes
コンパイル時間 152 ms
コンパイル使用メモリ 82,456 KB
実行使用メモリ 78,980 KB
最終ジャッジ日時 2024-04-27 08:37:38
合計ジャッジ時間 2,435 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
53,568 KB
testcase_01 AC 40 ms
53,320 KB
testcase_02 AC 40 ms
52,384 KB
testcase_03 AC 101 ms
78,576 KB
testcase_04 AC 118 ms
78,980 KB
testcase_05 AC 157 ms
77,376 KB
testcase_06 AC 150 ms
77,172 KB
testcase_07 AC 40 ms
52,576 KB
testcase_08 AC 62 ms
67,540 KB
testcase_09 AC 56 ms
67,672 KB
testcase_10 AC 57 ms
67,716 KB
testcase_11 AC 57 ms
67,108 KB
testcase_12 AC 165 ms
78,140 KB
testcase_13 AC 168 ms
77,472 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# 左側から必要な変更を?に行う、次は右側から必要な変更を?に行う
# それで3連続があればアウト

T = int(input())
for t in range(T):
    N = int(input())
    S = list(input())

    # from left
    for i in range(N):
        if S[i] == '?':
            # 1個前2個前双方ともに?のケースに注意
            if S[(i-2)%N] == S[(i-1)%N] == '0':
                S[i] = '1'
            if S[(i-2)%N] == S[(i-1)%N] == '1':
                S[i] = '0'

    # from right
    for i in range(N-1, -1, -1):
        if S[i] == '?':
            if S[(i+2)%N] == S[(i+1)%N] == '0':
                S[i] = '1'
            if S[(i+2)%N] == S[(i+1)%N] == '1':
                S[i] = '0'

    ans = 'Yes'
    for i in range(N):
        if S[(i-2)%N] == S[(i-1)%N] == S[(i)%N] == '0':
            ans = 'No'
        if S[(i-2)%N] == S[(i-1)%N] == S[(i)%N] == '1':
            ans = 'No'

    print(ans)

0