結果

問題 No.2283 Prohibit Three Consecutive
ユーザー jianglyjiangly
提出日時 2023-04-28 21:34:23
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 1,514 bytes
コンパイル時間 2,259 ms
コンパイル使用メモリ 198,716 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-11 06:34:19
合計ジャッジ時間 2,837 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>

using i64 = long long;

void solve() {
    int N;
    std::cin >> N;
    
    std::string S;
    std::cin >> S;
    
    for (int x = 0; x < 2; x++) {
        for (int y = 0; y < 2; y++) {
            if (S[0] == '0' + !x) {
                continue;
            }
            if (S[1] == '0' + !y) {
                continue;
            }
            
            std::array<std::array<bool, 2>, 2> dp{};
            dp[x][y] = true;
            
            for (int i = 2; i < N; i++) {
                std::array<std::array<bool, 2>, 2> g{};
                for (int x = 0; x < 2; x++) {
                    for (int y = 0; y < 2; y++) {
                        for (int z = 0; z < 2; z++) {
                            if (dp[x][y] && S[i] != '0' + !z && (x != y || y != z)) {
                                g[y][z] = true;
                            }
                        }
                    }
                }
                dp = g;
            }
            for (int t = 0; t < 2; t++) {
                for (int z = 0; z < 2; z++) {
                    if ((t != z || z != x) && (z != x || x != y) && dp[t][z]) {
                        std::cout << "Yes\n";
                        return;
                    }
                }
            }
        }
    }
    std::cout << "No\n";
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    int t;
    std::cin >> t;
    
    while (t--) {
        solve();
    }
    
    return 0;
}
0