結果
問題 | No.1431 東大文系数学2020第2問改 |
ユーザー |
![]() |
提出日時 | 2024-05-03 15:31:05 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 636 ms / 5,000 ms |
コード長 | 1,330 bytes |
コンパイル時間 | 997 ms |
コンパイル使用メモリ | 88,564 KB |
実行使用メモリ | 143,980 KB |
最終ジャッジ日時 | 2024-11-24 17:16:07 |
合計ジャッジ時間 | 11,092 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 28 |
ソースコード
#include <iostream>#include <vector>using namespace std;#define int long longconst int mod = 998244353;const int max_fact = 9000001;vector<long long> fact(max_fact);vector<long long> fact_inve(max_fact,1);void precompute() {fact[0] = 1;for (int i = 1; i < max_fact; ++i)fact[i] = (fact[i - 1] * i) % mod;fact_inve[max_fact - 1] = 921885471;for (int i = max_fact - 2; i > 0; --i)fact_inve[i] = (fact_inve[i + 1] * (i + 1)) % mod;}long long Comb(int a, int b) {if (a < b || b < 0)return 0;return (fact[a] * fact_inve[b] % mod * fact_inve[a - b]) % mod;}signed main() {int N, M, K;cin >> N >> M >> K;precompute();long long ans = 0;vector<long long> C(N + 1);vector<long long> CC(2 * N + 1);for (int i = 0; i <= N; ++i)C[i] = Comb(N, i);for (int i = 0; i <= 2 * N; ++i)CC[i] = Comb(i, K);for (int a = 0; a < N; ++a) {for (int b = 0; b < N; ++b) {if ((a + b) % 2 == K % 2)ans = (ans + (C[a] * C[b] % mod * Comb((N - a) * (N - b), M) % mod * CC[a + b]) % mod) % mod;elseans = (ans - (C[a] * C[b] % mod * Comb((N - a) * (N - b), M) % mod * CC[a + b]) % mod + mod) % mod;}}cout << ans << endl;return 0;}