結果

問題 No.1815 K色問題
ユーザー 259_Momone259_Momone
提出日時 2022-09-18 02:54:15
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 103 ms / 2,000 ms
コード長 1,366 bytes
コンパイル時間 3,536 ms
コンパイル使用メモリ 266,672 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-13 11:33:24
合計ジャッジ時間 4,650 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 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 1 ms
6,676 KB
testcase_06 AC 57 ms
6,676 KB
testcase_07 AC 15 ms
6,676 KB
testcase_08 AC 83 ms
6,676 KB
testcase_09 AC 10 ms
6,676 KB
testcase_10 AC 14 ms
6,676 KB
testcase_11 AC 25 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 103 ms
6,676 KB
testcase_15 AC 100 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/extc++.h>
#include <atcoder/modint>

int main() {
    using namespace std;
    using modint = atcoder::static_modint<1000000007>;
    unsigned long N, M, K;
    cin >> N >> M >> K;
    vector<modint> ans(K + 1);
    if(N == 1)for(unsigned long i{1}; i <= K; ++i)ans[i] = modint::raw(i) * modint::raw(i - 1).pow(M - 1);
    else if(N == 2)for(unsigned long i{1}; i <= K; ++i)ans[i] = modint{i * i - i} * modint{(i - 3) * i + 3}.pow(M - 1);
    else for(unsigned long i{1}; i <= K; ++i){
        const auto I{modint::raw(i)};
        auto a{(I - 2) * ((I - 3) * I + 5)};
        auto b{(I - 1) * (((I - 6) * I + 13) * I - 11)};
        auto c{I * (I - 1) * (I - 1)};
        auto d{I * (I - 1) * ((I - 3) * I + 1)};
        unsigned long n{M - 1};
        while(n){
            if(n & 1){
                c = a * c - d;
                d = b * d;
            }else{
                d = a * d - b * c;
            }
            a = a * a - 2 * b;
            b = b * b;
            n /= 2;
        }
        ans[i] = c;
    }
    vector<modint> coef(K + 1);
    coef[0] = 1;
    for(unsigned long i{}; i < K; ++i)coef[i + 1] = coef[i] * (K - i);
    modint c{1};
    for(unsigned long i{K + 1}; i; --i)coef[i - 1] *= (c *= -modint::raw(i));
    cout << (inner_product(begin(ans), end(ans), begin(coef), modint{}) / coef[K]).val() << endl;
    return 0;
}
0