結果

問題 No.1321 塗るめた
ユーザー trineutrontrineutron
提出日時 2020-12-18 11:18:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,213 bytes
コンパイル時間 1,943 ms
コンパイル使用メモリ 206,308 KB
実行使用メモリ 8,940 KB
最終ジャッジ日時 2023-10-21 07:57:38
合計ジャッジ時間 5,872 ms
ジャッジサーバーID
(参考情報)
judge13 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 25 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 2 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 2 ms
4,348 KB
testcase_12 TLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
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 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

constexpr int64_t mod = 998244353;

vector<int64_t> fact, inv;

int64_t power(int64_t n, int64_t k) {
    if (k == 0) return 1;
    int64_t res = power(n * n % mod, k / 2);
    if (k % 2) res = res * n % mod;
    return res;
}

void init(int64_t n) {
    fact.push_back(1);
    inv.push_back(1);
    for (int i = 1; i <= n; i++) {
        fact.push_back(i * fact.back() % mod);
        inv.push_back(power(fact.back(), mod - 2));
    }
}

int64_t ncr(int64_t n, int64_t r) {
    if (r < 0 or n < r) return 0;
    return fact[n] * inv[r] % mod * inv[n - r] % mod;
}

int64_t solve(int64_t n, int64_t m, int64_t k) {
    int64_t res = 0;
    for (int64_t i = 1; i <= n; i++) {
        res += ncr(n, i) * power(k, i) % mod * power(m, n - i);
        res %= mod;
    }
    return res;
}

int main() {
    int64_t n, m, k;
    cin >> n >> m >> k;
    init(n);
    int64_t ans = 0;
    for (int64_t i = 0; i < k; i++) {
        int64_t d = solve(n, m, k - i) * ncr(m, k - i) % mod * ncr(m - k + i, i) % mod;
        if (i % 2 == 0) {
            ans += d;
        } else {
            ans -= d;
        }
        ans %= mod;
    }
    cout << (ans + mod) % mod << endl;
}
0