結果
問題 | No.2527 H and W |
ユーザー |
![]() |
提出日時 | 2023-11-03 21:58:55 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 443 ms / 2,000 ms |
コード長 | 855 bytes |
コンパイル時間 | 4,336 ms |
コンパイル使用メモリ | 253,100 KB |
最終ジャッジ日時 | 2025-02-17 18:14:31 |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 23 |
ソースコード
#include <bits/stdc++.h>using namespace std;#include <atcoder/all>using mint = atcoder::modint998244353;int main() {constexpr int MAX_SIZE = 1<<21;vector<mint> factorial(MAX_SIZE, mint(1));vector<mint> factorial_inv(MAX_SIZE, mint(1));for( int i = 1; i < MAX_SIZE; i++ ) {factorial[i] = factorial[i-1]*i;factorial_inv[i] = factorial[i].inv();}auto binom = [&](int n, int r) -> mint {if( 0 <= r && r <= n ) return factorial[n]*factorial_inv[n-r]*factorial_inv[r];else return mint(0);};long long H, W, K;cin >> H >> W >> K;mint ans = 0;K = H*W-K;for( long long x = 0; x < H; x++ ) {if( (K-W*x)%(H-x) == 0 ) {long long y = (K-W*x)/(H-x);ans += binom(H, x)*binom(W, y);}}if( K == H*W ) {for( long long y = 0; y <= W; y++ ) {ans += binom(H, H)*binom(W, y);}}cout << ans.val() << endl;}