結果

問題 No.2668 Trees on Graph Paper
ユーザー suisensuisen
提出日時 2023-12-28 03:41:39
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 570 ms / 3,000 ms
コード長 1,485 bytes
コンパイル時間 626 ms
コンパイル使用メモリ 73,680 KB
実行使用メモリ 6,548 KB
最終ジャッジ日時 2024-02-11 22:15:45
合計ジャッジ時間 7,902 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 2 ms
6,548 KB
testcase_02 AC 2 ms
6,548 KB
testcase_03 AC 51 ms
6,548 KB
testcase_04 AC 2 ms
6,548 KB
testcase_05 AC 2 ms
6,548 KB
testcase_06 AC 2 ms
6,548 KB
testcase_07 AC 2 ms
6,548 KB
testcase_08 AC 2 ms
6,548 KB
testcase_09 AC 2 ms
6,548 KB
testcase_10 AC 2 ms
6,548 KB
testcase_11 AC 2 ms
6,548 KB
testcase_12 AC 1 ms
6,548 KB
testcase_13 AC 2 ms
6,548 KB
testcase_14 AC 336 ms
6,548 KB
testcase_15 AC 513 ms
6,548 KB
testcase_16 AC 262 ms
6,548 KB
testcase_17 AC 28 ms
6,548 KB
testcase_18 AC 490 ms
6,548 KB
testcase_19 AC 422 ms
6,548 KB
testcase_20 AC 456 ms
6,548 KB
testcase_21 AC 439 ms
6,548 KB
testcase_22 AC 444 ms
6,548 KB
testcase_23 AC 285 ms
6,548 KB
testcase_24 AC 564 ms
6,548 KB
testcase_25 AC 570 ms
6,548 KB
testcase_26 AC 566 ms
6,548 KB
testcase_27 AC 564 ms
6,548 KB
testcase_28 AC 2 ms
6,548 KB
testcase_29 AC 2 ms
6,548 KB
testcase_30 AC 2 ms
6,548 KB
testcase_31 AC 2 ms
6,548 KB
testcase_32 AC 1 ms
6,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <array>
#include <iostream>

#include <atcoder/modint>

int main() {
    using mint = atcoder::modint;

    int n, m;
    std::cin >> n >> m;

    mint::set_mod(m);

    mint ans = 1;

    std::array<std::array<mint, 2>, 2> pd{};
    pd[0][0] = { 1 };
    for (int x = 0; x < 2 * n - 3; ++x) {
        // pd: dp(x,*,*), dp: dp(x+1,*,*)
        std::array<std::array<mint, 2>, 2> dp{};
        for (int f : { 0, 1 }) {
            // T: tofu, R: red ball, W: white ball

            // g=0 (RTRT...RT)
            {
                constexpr int g = 0;
                const mint val = pd[f][g];
                // W
                dp[0][0] += val;
                // R
                dp[1][1] += val;
            }
            // g=1 (RTRT...TR)
            {
                constexpr int g = 1;
                const mint val = pd[f][g];
                // W
                dp[0][1] += val;
                // TR
                mint weightR = f ? 1 : x; // if f=0 then vertex (x,_) has degree of 1
                dp[1][1] += val * weightR;
                // TW
                mint weightW = weightR * (x + 1); // vertex (x+1,_) has degree of 1
                dp[0][0] += val * weightW;
            }
        }
        dp.swap(pd);

        if (x % 2 == 0) {
            // level x/2+1
            ans *= pd[0][1] + pd[1][1];
        }
    }
    // level n
    for (int x = 1; x <= 2 * n - 1; ++x) {
        ans *= x;
    }

    std::cout << ans.val() << std::endl;
}
0