結果

問題 No.2668 Trees on Graph Paper
ユーザー 👑 hitonanodehitonanode
提出日時 2024-03-09 09:57:51
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,232 ms / 3,000 ms
コード長 1,127 bytes
コンパイル時間 1,110 ms
コンパイル使用メモリ 84,724 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-09 09:58:07
合計ジャッジ時間 15,463 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 107 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 1 ms
6,676 KB
testcase_06 AC 1 ms
6,676 KB
testcase_07 AC 1 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 1 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 1 ms
6,676 KB
testcase_14 AC 749 ms
6,676 KB
testcase_15 AC 1,138 ms
6,676 KB
testcase_16 AC 558 ms
6,676 KB
testcase_17 AC 57 ms
6,676 KB
testcase_18 AC 1,055 ms
6,676 KB
testcase_19 AC 931 ms
6,676 KB
testcase_20 AC 997 ms
6,676 KB
testcase_21 AC 934 ms
6,676 KB
testcase_22 AC 976 ms
6,676 KB
testcase_23 AC 609 ms
6,676 KB
testcase_24 AC 1,231 ms
6,676 KB
testcase_25 AC 1,231 ms
6,676 KB
testcase_26 AC 1,232 ms
6,676 KB
testcase_27 AC 1,232 ms
6,676 KB
testcase_28 AC 1 ms
6,676 KB
testcase_29 AC 2 ms
6,676 KB
testcase_30 AC 2 ms
6,676 KB
testcase_31 AC 2 ms
6,676 KB
testcase_32 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <array>
#include <iostream>
using namespace std;

#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define REP(i, n) FOR(i,0,n)

using Mat = std::array<long long, 9>;

int M;
Mat operator*(const Mat &a, const Mat &b) {
    Mat ret{};
    REP(i, 3) REP(j, 3) {
        auto v = a[i * 3 + 0] * b[0 * 3 + j] + a[i * 3 + 1] * b[1 * 3 + j] + a[i * 3 + 2] * b[2 * 3 + j];
        ret[i * 3 + j] = v % M;
    }
    return ret;
}

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

    Mat dp1, trans1;
    dp1.fill(0);
    dp1[0] = dp1[4] = dp1[8] = 1;

    trans1.fill(1);
    trans1[2] = 0;

    auto setter = [&](long long i) {
        trans1[1 * 3 + 0] = i + 1;
        trans1[2 * 3 + 0] = i * (i + 1) % M;
        trans1[2 * 3 + 1] = i;
    };

    long long ret = 1;

    REP(i, N - 1) {
        setter(i * 2);
        dp1 = trans1 * dp1;

        setter(i * 2 + 1);
        dp1 = trans1 * dp1;

        ret = ret * dp1[0 * 3 + 2] % M;
    }

    FOR(i, 1, N * 2) ret = ret * i % M;
    cout << ret << '\n';
}
0