結果

問題 No.1492 01文字列と転倒
ユーザー MisterMister
提出日時 2021-05-01 01:18:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 534 ms / 4,000 ms
コード長 1,144 bytes
コンパイル時間 930 ms
コンパイル使用メモリ 80,152 KB
実行使用メモリ 10,944 KB
最終ジャッジ日時 2023-09-26 10:17:58
合計ジャッジ時間 6,327 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 534 ms
10,916 KB
testcase_03 AC 497 ms
10,432 KB
testcase_04 AC 448 ms
10,236 KB
testcase_05 AC 374 ms
9,200 KB
testcase_06 AC 392 ms
9,304 KB
testcase_07 AC 439 ms
9,844 KB
testcase_08 AC 531 ms
10,944 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 390 ms
9,372 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 7 ms
4,380 KB
testcase_17 AC 375 ms
9,268 KB
testcase_18 AC 8 ms
4,380 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 5 ms
4,380 KB
testcase_21 AC 312 ms
8,524 KB
testcase_22 AC 8 ms
4,380 KB
testcase_23 AC 4 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <atcoder/modint>
#include <iostream>
#include <vector>

using namespace std;
using mint = atcoder::modint;

void solve() {
    int n;
    {
        int m;
        cin >> n >> m;
        mint::set_mod(m);
    }

    auto dp = vector(n + 1, vector(n * n + 1, mint(0)));
    dp[0][0] = 1;
    // 高さ、転倒数
    for (int l = 0; l < n * 2; ++l) {
        auto ndp = vector(n + 1, vector(n * n + 1, mint(0)));

        // l(長さ)とi(高さ)の偶奇は一致
        for (int i = l % 2; i <= n && i <= l; i += 2) {
            int o = (l - i) / 2;  // 1の個数

            for (int r = 0; r <= n * n; ++r) {
                // 0を置く場合
                if (r + o <= n * n && i + 1 <= n) {
                    ndp[i + 1][r + o] += dp[i][r];
                }

                // 1を置く場合
                if (i - 1 >= 0) {
                    ndp[i - 1][r] += dp[i][r];
                }
            }
        }

        swap(dp, ndp);
    }

    for (int r = 0; r <= n * n; ++r) cout << dp[0][r].val() << "\n";
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    solve();

    return 0;
}
0