結果

問題 No.2040 010-1 Deletion
ユーザー CyanmondCyanmond
提出日時 2022-08-12 23:19:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,714 bytes
コンパイル時間 2,305 ms
コンパイル使用メモリ 216,308 KB
実行使用メモリ 12,908 KB
最終ジャッジ日時 2023-10-24 11:40:13
合計ジャッジ時間 8,002 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 WA -
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 TLE -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using i64 = long long;

#include "atcoder/modint"
using Fp = atcoder::modint998244353;

int main() {
    int N; std::cin >> N;
    std::string S; std::cin >> S;
    std::vector<int> zero_ids;
    for (int i = 0; i < N; ++i) if (S[i] == '0') zero_ids.push_back(i);
    std::vector dp(N, std::vector(N, Fp(0)));
    std::vector is_seen(N, std::vector(N, false));

    auto solve = [&](auto &&self, const int l, const int r) -> Fp {
        if (r - l + 1 < 3) return 0;
        if (is_seen[l][r]) return dp[l][r];
        is_seen[l][r] = true;
        if (S[l] == '1' or S[r] == '1') return dp[l][r] = 0;
        if (S[l + 1] == '0' and S[r - 1] == '0') return dp[l][r] = 0;

        Fp res = 0;
        for (int nl = l + 1; nl != r; ++nl) {
            if (S[nl] != '1') for (int nr = r - 1; nr != nl; --nr) {
                if (S[nr] != '1') res += self(self, nl, nr);
                if (S[nr] == '0') break;
            }
            if (S[nl] == '0') break;
        }
        const auto itr = std::lower_bound(zero_ids.begin(), zero_ids.end(), l + 1);
        if (itr == zero_ids.end() or *itr >= r) ++res;
        return dp[l][r] = res;
    };

    for (int i = 0; i < N; ++i) for (int j = i; j < N; ++j) solve(solve, i, j);
    std::vector<Fp> dp2_a(N + 1, Fp(0)), dp2_b(N + 1, Fp(0));
    dp2_a[0] = 1;
    for (int i = 0; i < N; ++i) {
        const auto itr = std::lower_bound(zero_ids.begin(), zero_ids.end(), i);
        for (int j = i + 1; j <= N; ++j) {
            dp2_a[j] += (dp2_a[i] + dp2_b[i]) * dp[i][j - 1];
            if (itr == zero_ids.end() or *itr >= j) dp2_b[j] += dp2_a[i];
        }
    }
    std::cout << (dp2_a[N] + dp2_b[N]).val() << std::endl;
    // ??
}
0