結果

問題 No.2668 Trees on Graph Paper
ユーザー ゼットゼット
提出日時 2024-03-08 23:21:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,468 bytes
コンパイル時間 829 ms
コンパイル使用メモリ 82,620 KB
実行使用メモリ 813,956 KB
最終ジャッジ日時 2024-03-08 23:22:04
合計ジャッジ時間 5,941 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 351 ms
98,828 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 MLE -
testcase_15 MLE -
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 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>

using namespace std;

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

    vector<vector<long long>> dp(2 * N, vector<long long>(3, 0));
    vector<vector<long long>> score(2 * N, vector<long long>(3, 0));

    dp[1][2] = 1;
    score[1][2] = 1;

    for (int i = 1; i < 2 * N - 1; ++i) {
        for (int j = 0; j < 3; ++j) {
            for (int k = 0; k < 3; ++k) {
                if (j == 2 && k == 0) {
                    continue;
                }
                dp[i + 1][k] += dp[i][j];
                dp[i + 1][k] %= mod;
                if (k <= j) {
                    score[i + 1][k] += score[i][j];
                } else if (k == 1 && j == 0) {
                    score[i + 1][k] += score[i][j] * (i - 1);
                } else if (k == 2 && j == 1) {
                    score[i + 1][k] += score[i][j] * i;
                } else {
                    long long w = score[i][j] * i;
                    w %= mod;
                    w *= i - 1;
                    w %= mod;
                    score[i + 1][k] += w;
                }
                score[i + 1][k] %= mod;
            }
        }
    }

    long long result = 1;
    for (int x = 1; x < 2 * N; ++x) {
        result *= x;
        result %= mod;
    }
    for (int i = 1; i < N; ++i) {
        result *= score[2 * i + 1][0];
        result %= mod;
    }

    cout << result << endl;

    return 0;
}
0