結果

問題 No.2527 H and W
ユーザー ripityripity
提出日時 2023-11-03 21:58:55
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 330 ms / 2,000 ms
コード長 855 bytes
コンパイル時間 8,970 ms
コンパイル使用メモリ 264,496 KB
実行使用メモリ 19,604 KB
最終ジャッジ日時 2023-11-03 21:59:21
合計ジャッジ時間 14,357 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 297 ms
19,604 KB
testcase_01 AC 285 ms
19,604 KB
testcase_02 AC 330 ms
19,604 KB
testcase_03 AC 297 ms
19,604 KB
testcase_04 AC 310 ms
19,604 KB
testcase_05 AC 309 ms
19,604 KB
testcase_06 AC 309 ms
19,604 KB
testcase_07 AC 295 ms
19,604 KB
testcase_08 AC 307 ms
19,604 KB
testcase_09 AC 294 ms
19,604 KB
testcase_10 AC 298 ms
19,604 KB
testcase_11 AC 309 ms
19,604 KB
testcase_12 AC 308 ms
19,604 KB
testcase_13 AC 330 ms
19,604 KB
testcase_14 AC 306 ms
19,604 KB
testcase_15 AC 306 ms
19,604 KB
testcase_16 AC 309 ms
19,604 KB
testcase_17 AC 310 ms
19,604 KB
testcase_18 AC 324 ms
19,604 KB
testcase_19 AC 305 ms
19,604 KB
testcase_20 AC 305 ms
19,604 KB
testcase_21 AC 310 ms
19,604 KB
testcase_22 AC 315 ms
19,604 KB
testcase_23 AC 309 ms
19,604 KB
testcase_24 AC 305 ms
19,604 KB
testcase_25 AC 299 ms
19,604 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0