結果

問題 No.2283 Prohibit Three Consecutive
ユーザー JlyfishJlyfish
提出日時 2023-05-05 13:33:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,424 bytes
コンパイル時間 2,184 ms
コンパイル使用メモリ 201,068 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-02 09:55:04
合計ジャッジ時間 2,967 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#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