結果

問題 No.2283 Prohibit Three Consecutive
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-04-30 23:20:46
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 44 ms / 2,000 ms
コード長 1,070 bytes
コンパイル時間 987 ms
コンパイル使用メモリ 107,092 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-30 01:58:52
合計ジャッジ時間 1,777 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 11 ms
5,376 KB
testcase_04 AC 11 ms
5,376 KB
testcase_05 AC 26 ms
5,376 KB
testcase_06 AC 26 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 8 ms
5,376 KB
testcase_09 AC 7 ms
5,376 KB
testcase_10 AC 7 ms
5,376 KB
testcase_11 AC 7 ms
5,376 KB
testcase_12 AC 21 ms
5,376 KB
testcase_13 AC 44 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>
#include <deque>
#include <complex>
#include <cassert>

using namespace std;
using ll = long long;

void solve(){
    ll N, a, b;
    string S;
    cin >> N >> S;
    for (int i=0; i<N; i++){
        if (S[i] != '?') continue;
        a = (i-2+N) % N;
        b = (i-1+N) % N;
        if (S[a] == S[b] && S[a] != '?'){
            S[i] = (S[a] == '1' ? '0' : '1');
        }
    }
    for (int i=N-1; i>=0; i--){
        if (S[i] != '?') continue;
        a = (i+1) % N;
        b = (i+2) % N;
        if (S[a] == S[b] && S[a] != '?'){
            S[i] = (S[a] == '1' ? '0' : '1');
        }
    }

    for (int i=0; i<N; i++){
        if (S[i] != '?' && S[i] == S[(i+1)%N] && S[(i+1)%N] == S[(i+2)%N]){
            cout << "No" << endl;
            return;
        }
    }
    cout << "Yes" << endl;
}

int main(){

    int T;
    cin >> T;
    while(T){
        T--;
        solve();
    }

    return 0;
}
0