結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 WA -
testcase_03 AC 78 ms
13,964 KB
testcase_04 AC 100 ms
11,908 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 29 ms
21,376 KB
testcase_09 AC 45 ms
21,332 KB
testcase_10 AC 27 ms
21,248 KB
testcase_11 AC 43 ms
21,204 KB
testcase_12 WA -
testcase_13 WA -
権限があれば一括ダウンロードができます

ソースコード

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(y==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