結果

問題 No.2283 Prohibit Three Consecutive
ユーザー HIcoderHIcoder
提出日時 2023-07-06 23:40:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 47 ms / 2,000 ms
コード長 1,038 bytes
コンパイル時間 1,052 ms
コンパイル使用メモリ 99,496 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-28 00:40:10
合計ジャッジ時間 3,042 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<set>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<numeric>
#include<queue>
#include<cmath>
using namespace std;
typedef long long ll;
const ll INF=1LL<<60;
typedef pair<int,int> P;
typedef pair<int,P> PP;
const ll MOD=998244353;
const double PI=acos(-1);


bool solve(int N,string S){


    for(int t=0;t<2;t++){
        for(int i=0;i<2*N;i++){
            if(S[i%N]!='?' && (S[i%N]==S[(i+1)%N] && S[(i+2)%N]=='?'))
            {
                S[(i+2)%N]=(char)((1-(S[i%N]-'0'))+'0');
            }

        }
        reverse(S.begin(),S.end());
    }



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

    return true;

}


int main(){
    int T;
    cin>>T;
    for(int t=0;t<T;t++){
        int N;
        cin>>N;
        string S;
        cin>>S;
        bool flag=solve(N,S);

        cout<<(flag?"Yes":"No")<<endl;
        


    }//テストケースtの終了
}
0