結果
| 問題 |
No.1321 塗るめた
|
| コンテスト | |
| ユーザー |
trineutron
|
| 提出日時 | 2020-12-18 11:18:27 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,213 bytes |
| コンパイル時間 | 2,768 ms |
| コンパイル使用メモリ | 196,604 KB |
| 最終ジャッジ日時 | 2025-01-17 02:51:30 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 18 TLE * 27 |
ソースコード
#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;
}
trineutron