結果
| 問題 | 
                            No.2283 Prohibit Three Consecutive
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2023-04-28 21:36:42 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,617 bytes | 
| コンパイル時間 | 1,756 ms | 
| コンパイル使用メモリ | 169,524 KB | 
| 実行使用メモリ | 5,248 KB | 
| 最終ジャッジ日時 | 2024-11-17 20:34:32 | 
| 合計ジャッジ時間 | 2,219 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | AC * 2 WA * 11 | 
ソースコード
#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';
    }
}