結果
| 問題 |
No.1691 Badugi
|
| コンテスト | |
| ユーザー |
👑 |
| 提出日時 | 2021-09-12 15:50:46 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 9 ms / 2,000 ms |
| コード長 | 2,177 bytes |
| コンパイル時間 | 189 ms |
| コンパイル使用メモリ | 32,116 KB |
| 実行使用メモリ | 9,600 KB |
| 最終ジャッジ日時 | 2024-07-05 09:52:40 |
| 合計ジャッジ時間 | 1,059 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 17 |
ソースコード
#include <stdio.h>
const int Mod = 998244353;
long long fact[500001], fact_inv[500001];
long long div_mod(long long x, long long y, long long z)
{
if (x % y == 0) return x / y;
else return (div_mod((1 + x / y) * y - x, (z % y), y) * z + x) / y;
}
long long combination(int n, int k)
{
if (k < 0 || n < k) return 0;
return fact[n] * fact_inv[k] % Mod * fact_inv[n-k] % Mod;
}
int main()
{
int i, N, M, K;
scanf("%d %d %d", &N, &M, &K);
if (N < M) {
N ^= M;
M ^= N;
N ^= M;
}
for (i = 1, fact[0] = 1; i <= N; i++) fact[i] = fact[i-1] * i % Mod;
for (i = N - 1, fact_inv[N] = div_mod(1, fact[N], Mod); i >= 0; i--) fact_inv[i] = fact_inv[i+1] * (i + 1) % Mod;
long long ans[5] = {combination(N, K - 2) * combination(M, K - 2) % Mod * fact[K-2] % Mod};
if (K - 2 >= 4) ans[1] += ans[0] * combination(K - 2, 4) % Mod * 12 % Mod;
if (K - 2 >= 3) {
ans[1] += ans[0] * combination(K - 2, 3) % Mod * 12 % Mod;
if (M >= K - 1) ans[2] += ans[0] * combination(K - 2, 3) % Mod * (M - K + 2) * 6 % Mod;
if (N >= K - 1) ans[2] += ans[0] * combination(K - 2, 3) % Mod * (N - K + 2) * 6 % Mod;
}
if (K - 2 >= 2) {
ans[2] += ans[0] * combination(K - 2, 2) % Mod;
if (M >= K - 1) {
ans[2] += ans[0] * combination(K - 2, 2) % Mod * (M - K + 2) * 2 % Mod;
ans[3] += ans[0] * combination(K - 2, 2) % Mod * (M - K + 2) * 3 % Mod;
}
if (N >= K - 1) {
ans[2] += ans[0] * combination(K - 2, 2) % Mod * (N - K + 2) * 2 % Mod;
ans[3] += ans[0] * combination(K - 2, 2) % Mod * (N - K + 2) * 3 % Mod;
}
if (M >= K) ans[4] += ans[0] * combination(K - 2, 2) % Mod * combination(M - K + 2, 2) * 2 % Mod;
if (M >= K - 1 && N >= K - 1) ans[4] += ans[0] * combination(K - 2, 2) % Mod * (M - K + 2) % Mod * (N - K + 2) * 2 % Mod;
if (N >= K) ans[4] += ans[0] * combination(K - 2, 2) % Mod * combination(N - K + 2, 2) * 2 % Mod;
}
if (M >= K) ans[3] += ans[0] * (K - 2) % Mod * combination(M - K + 2, 2) % Mod;
if (N >= K) ans[3] += ans[0] * (K - 2) % Mod * combination(N - K + 2, 2) % Mod;
printf("%lld\n", (ans[1] + div_mod(ans[2] % Mod, 2, Mod) + div_mod(ans[3] % Mod, 3, Mod) + div_mod(ans[4] % Mod, 4, Mod)) % Mod);
fflush(stdout);
return 0;
}