結果

問題 No.2283 Prohibit Three Consecutive
コンテスト
ユーザー Jlyfish
提出日時 2023-05-05 13:33:04
言語 C++17(gcc12)
(gcc 12.4.0 + boost 1.90.0)
コンパイル:
g++-12 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 1,424 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,489 ms
コンパイル使用メモリ 201,908 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-06-30 12:05:10
合計ジャッジ時間 2,523 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 8 WA * 5
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>

using namespace std;

const int N = 200010;

int n;
bool dp[N][2][2];
char s[N];

void Solution() {
    cin >> n >> (s + 1);
    for (int i = n + 1; i <= (n << 1); i++) {
        s[i] = s[i - n];
    }
    n <<= 1;
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j < 2; j++) {
            for (int k = 0; k < 2; k++) {
                dp[i][j][k] = false;
            }
        }
    }
    
    for (int i = 1; i <= n; i++) {
        for (int p = 0; p < 2; p++) {
            // dp[i - 1][p][j] -> dp[i][j][k]
            for (int j = 0; j < 2; j++) {
                auto upd = [&](int k) {
                    if (j == p && j == k) return;
                    dp[i][j][k] |= dp[i - 1][p][j];
                };
                if (s[i] == '?') {
                    for (int k = 0; k < 2; k++) upd(k);
                } else {
                    upd(s[i] - '0');
                }
            }
        }
    }
    
    bool ans = false;
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < 2; j++) {
            ans |= dp[n][i][j];
        }
    }
    cout << (ans ? "Yes" : "No") << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < 2; j++) {
            dp[0][i][j] = true;
        }
    }
    
    int testCase;
    cin >> testCase;
    while (testCase--) Solution();
    return 0;
}
0