結果

問題 No.2668 Trees on Graph Paper
ユーザー ゼットゼット
提出日時 2024-03-08 23:29:46
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2,730 ms / 3,000 ms
コード長 1,442 bytes
コンパイル時間 766 ms
コンパイル使用メモリ 81,344 KB
実行使用メモリ 6,548 KB
最終ジャッジ日時 2024-03-08 23:30:17
合計ジャッジ時間 30,123 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 235 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 1 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 1,613 ms
6,548 KB
testcase_15 AC 2,452 ms
6,548 KB
testcase_16 AC 1,233 ms
6,548 KB
testcase_17 AC 116 ms
6,548 KB
testcase_18 AC 2,255 ms
6,548 KB
testcase_19 AC 1,951 ms
6,548 KB
testcase_20 AC 2,104 ms
6,548 KB
testcase_21 AC 2,076 ms
6,548 KB
testcase_22 AC 2,095 ms
6,548 KB
testcase_23 AC 1,321 ms
6,548 KB
testcase_24 AC 2,647 ms
6,548 KB
testcase_25 AC 2,680 ms
6,548 KB
testcase_26 AC 2,682 ms
6,548 KB
testcase_27 AC 2,730 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 2 ms
6,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

using namespace std;

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

    vector<long long> dp(3, 0);
    dp[2] = 1;
    vector<long long> score(3, 0);
    score[2] = 1;

    long long result = 1;
    for (int x = 1; x < 2 * N; ++x) {
        result *= x;
        result %= mod;
    }

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

    cout << result << endl;

    return 0;
}
0