結果

問題 No.2527 H and W
ユーザー GOTKAKOGOTKAKO
提出日時 2023-11-03 22:03:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 59 ms / 2,000 ms
コード長 1,120 bytes
コンパイル時間 2,127 ms
コンパイル使用メモリ 206,004 KB
実行使用メモリ 26,688 KB
最終ジャッジ日時 2023-11-03 22:04:02
合計ジャッジ時間 4,227 ms
ジャッジサーバーID
(参考情報)
judge10 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 56 ms
26,688 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 55 ms
26,688 KB
testcase_05 AC 56 ms
26,688 KB
testcase_06 AC 55 ms
26,688 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 55 ms
26,688 KB
testcase_09 AC 56 ms
26,688 KB
testcase_10 AC 57 ms
26,688 KB
testcase_11 AC 56 ms
26,688 KB
testcase_12 AC 59 ms
26,688 KB
testcase_13 AC 55 ms
26,688 KB
testcase_14 AC 55 ms
26,688 KB
testcase_15 AC 54 ms
26,688 KB
testcase_16 AC 55 ms
26,688 KB
testcase_17 AC 53 ms
26,688 KB
testcase_18 AC 55 ms
26,688 KB
testcase_19 AC 33 ms
17,180 KB
testcase_20 AC 37 ms
19,488 KB
testcase_21 AC 55 ms
26,688 KB
testcase_22 AC 55 ms
26,688 KB
testcase_23 AC 55 ms
26,688 KB
testcase_24 AC 35 ms
18,500 KB
testcase_25 AC 46 ms
23,048 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    long long H,W,K; cin >> H >> W >> K;
    long long mod = 998244353;
    if(H < W) swap(H,W);

    vector<long long> fac(H+1,1),inv(H+1),facinv(H+1,1);
    for(int i=1; i<=H; i++) fac.at(i) = fac.at(i-1)*i%mod;
    inv.at(1) = 1;
    for(int i=2; i<=H; i++) inv.at(i) = mod-(mod/i*inv.at(mod%i)%mod);
    for(int i=1; i<=H; i++) facinv.at(i) = facinv.at(i-1)*inv.at(i)%mod;

    long long answer = 0;
    for(int i=0; i<H; i++){
        long long h = fac.at(H)*facinv.at(H-i)%mod*facinv.at(i)%mod,leftK = H*W-W*i-K;
        if(leftK%(H-i) != 0 || leftK < 0) continue;
        long long w = leftK/(H-i);
        w = fac.at(W)*facinv.at(W-w)%mod*facinv.at(w)%mod;
        answer = (answer+h*w)%mod;
    }
    if(K == 0){
        long long power2 = 1;
        for(int i=0; i<H; i++) power2 = power2*2%mod;
        answer += power2;
        power2 = 1;
        for(int i=0; i<W; i++) power2 = power2*2%mod;
        answer += power2;
        answer = (answer-1)%mod;
    }
    cout << answer << endl;
}
0