結果

問題 No.2283 Prohibit Three Consecutive
ユーザー t98slidert98slider
提出日時 2023-04-28 21:36:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,617 bytes
コンパイル時間 1,776 ms
コンパイル使用メモリ 166,780 KB
実行使用メモリ 4,516 KB
最終ジャッジ日時 2023-08-11 06:36:35
合計ジャッジ時間 2,722 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
	ios::sync_with_stdio(false);
    cin.tie(0);
    int T;
    cin >> T;
    while(T--){
        int n;
        string s;
        cin >> n >> s;
        bool ans = false;
        for(int st = 0; st < 4; st++){
            if(s[0] != '?' && (st & 1) != s[0] - '0') continue;
            if(s[1] != '?' && (st >> 1 & 1) != s[1] - '0') continue;
            vector<array<bool, 4>> dp(n + 1, array<bool, 4>({0, 0, 0, 0}));
            dp[2][st] = true;
            for(int i = 2; i < n; i++){
                if(s[i] != '?'){
                    int nv = s[i] - '0';
                    for(int j = 0; j < 4; j++){
                        if(!dp[i][j]) continue;
                        int ns = nv * 4 + j;
                        if(ns == 0 || ns == 7) continue;
                        dp[i + 1][ns / 2] = true;
                    }
                }else{
                    for(int j = 0; j < 4; j++){
                        if(!dp[i][j]) continue;
                        if(j != 0) dp[i + 1][j / 2] = true;
                        if(j + 4 != 7) dp[i + 1][j / 2] = true;
                    }
                }
            }
            for(int j = 0; j < 4; j++){
                if(!dp[n][j]) continue;
                int s1 = (st & 1) * 4 + j;
                int s2 = st * 2 + j / 2; 
                if(s1 != 0 && s1 != 7 && s2 != 0 && s2 != 7){
                    ans = true;
                    break;
                }
            }
            if(ans) break;
        }
        cout << (ans ? "Yes" : "No") << '\n';
    }
}
0