結果

問題 No.2528 pop_(backfront or not)
ユーザー 👑 hitonanodehitonanode
提出日時 2023-11-03 22:12:51
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,181 ms / 2,000 ms
コード長 765 bytes
コンパイル時間 1,088 ms
コンパイル使用メモリ 94,808 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-11-03 22:13:00
合計ジャッジ時間 8,590 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 4 ms
4,348 KB
testcase_06 AC 7 ms
4,348 KB
testcase_07 AC 18 ms
4,348 KB
testcase_08 AC 28 ms
4,348 KB
testcase_09 AC 88 ms
4,348 KB
testcase_10 AC 283 ms
4,348 KB
testcase_11 AC 305 ms
4,348 KB
testcase_12 AC 459 ms
4,348 KB
testcase_13 AC 487 ms
4,348 KB
testcase_14 AC 602 ms
4,348 KB
testcase_15 AC 937 ms
4,348 KB
testcase_16 AC 1,174 ms
4,348 KB
testcase_17 AC 1,181 ms
4,348 KB
testcase_18 AC 1,177 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <atcoder/modint>
#include <iostream>
#include <vector>
using namespace std;
using mint = atcoder::modint998244353;

int main() {
    int N;
    cin >> N;

    vector<mint> dp{1};

    while ((int)dp.size() < N * 2 + 1) {
        vector<mint> dpnxt(dp.size() + 2);
        for (int i = 0; i < (int)dpnxt.size(); ++i) {
            if (i and i + 1 < (int)dpnxt.size()) dpnxt.at(i) += dp.at(i - 1);
            const int l = i - 1, r = (int)dpnxt.size() - 1 - i - 1;
            if (l > 1) dpnxt.at(i) += dp.at(i - 2) * l * (l - 1) / 2;
            if (r > 1) dpnxt.at(i) += dp.at(i) * r * (r - 1) / 2;
            if (l > 0 and r > 0) dpnxt.at(i) += dp.at(i - 1) * l * r;
        }
        dp = dpnxt;
    }

    for (auto x : dp) cout << x.val() << '\n';
}
0