結果

問題 No.2283 Prohibit Three Consecutive
ユーザー otoshigootoshigo
提出日時 2023-04-28 23:26:44
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 110 ms / 2,000 ms
コード長 1,410 bytes
コンパイル時間 776 ms
コンパイル使用メモリ 85,068 KB
実行使用メモリ 21,376 KB
最終ジャッジ日時 2024-04-29 00:36:09
合計ジャッジ時間 1,816 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 83 ms
14,084 KB
testcase_04 AC 110 ms
11,908 KB
testcase_05 AC 54 ms
6,940 KB
testcase_06 AC 53 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 34 ms
21,248 KB
testcase_09 AC 54 ms
21,328 KB
testcase_10 AC 33 ms
21,376 KB
testcase_11 AC 50 ms
21,332 KB
testcase_12 AC 16 ms
6,944 KB
testcase_13 AC 37 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
template<class T> bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;}
template<class T> bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;}

void solve(){
    int n;
    string s;
    cin>>n>>s;
    rep(x,2)rep(y,2){
        if((s[0]!='?'&&s[0]-'0'!=x)||(s[1]!='?'&&s[1]-'0'!=y))continue;
        vector dp(n,vector<vector<bool>>(2,vector<bool>(2)));
        dp[1][x][y]=true;
        for(int i=2;i<n;i++){
            if(s[i]!='0'){
                dp[i][0][1]=dp[i-1][0][0]||dp[i-1][1][0];
                dp[i][1][1]=dp[i-1][0][1];
            }
            if(s[i]!='1'){
                dp[i][0][0]=dp[i-1][1][0];
                dp[i][1][0]=dp[i-1][0][1]||dp[i-1][1][1];
            }
        }
        bool flag=false;
        rep(i,2)rep(j,2){
            if(x==y&&y==j)continue;
            if(x==i&&i==j)continue;
            if(dp[n-1][i][j])flag=true;
        }
        if(flag){
            cout<<"Yes"<<"\n";
            return;
        }
    }
    cout<<"No"<<"\n";
}

int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    int t;
    cin>>t;
    while(t--){
        solve();
    }
}
0