結果

問題 No.2527 H and W
ユーザー maeshunmaeshun
提出日時 2023-11-11 16:13:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 56 ms / 2,000 ms
コード長 3,269 bytes
コンパイル時間 4,749 ms
コンパイル使用メモリ 266,448 KB
実行使用メモリ 18,516 KB
最終ジャッジ日時 2023-11-11 16:14:05
合計ジャッジ時間 7,397 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 51 ms
18,516 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 53 ms
18,516 KB
testcase_06 AC 55 ms
18,236 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 51 ms
18,516 KB
testcase_09 AC 35 ms
16,756 KB
testcase_10 AC 40 ms
18,516 KB
testcase_11 AC 53 ms
18,268 KB
testcase_12 AC 55 ms
16,672 KB
testcase_13 AC 55 ms
16,672 KB
testcase_14 AC 52 ms
18,332 KB
testcase_15 AC 56 ms
16,672 KB
testcase_16 AC 51 ms
18,516 KB
testcase_17 AC 51 ms
18,516 KB
testcase_18 AC 51 ms
18,516 KB
testcase_19 AC 36 ms
16,672 KB
testcase_20 AC 39 ms
14,788 KB
testcase_21 AC 53 ms
17,396 KB
testcase_22 AC 51 ms
16,672 KB
testcase_23 AC 52 ms
16,932 KB
testcase_24 AC 36 ms
16,672 KB
testcase_25 AC 37 ms
17,356 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
#define rep(i, n) for(int i=0;i<(n);++i)
#define rep1(i, n) for(int i=1;i<=(n);i++)
#define ll long long
using mint = modint998244353;
using P = pair<ll,ll>;
using lb = long double;
using T = tuple<ll, ll, ll>;
#ifdef LOCAL
#  include <debug_print.hpp>
#  define dbg(...) debug_print::multi_print(#__VA_ARGS__, __VA_ARGS__)
#else
#  define dbg(...) (static_cast<void>(0))
#endif

// combination mod prime
// https://youtu.be/8uowVvQ_-Mo?t=6002
// https://youtu.be/Tgd_zLfRZOQ?t=9928
struct modinv {
  int n; vector<mint> d;
  modinv(): n(2), d({0,1}) {}
  mint operator()(int i) {
    while (n <= i) d.push_back(-d[mint::mod()%n]*(mint::mod()/n)), ++n;
    return d[i];
  }
  mint operator[](int i) const { return d[i];}
} invs;
struct modfact {
  int n; vector<mint> d;
  modfact(): n(2), d({1,1}) {}
  mint operator()(int i) {
    while (n <= i) d.push_back(d.back()*n), ++n;
    return d[i];
  }
  mint operator[](int i) const { return d[i];}
} facts;
struct modfactinv {
  int n; vector<mint> d;
  modfactinv(): n(2), d({1,1}) {}
  mint operator()(int i) {
    while (n <= i) d.push_back(d.back()*invs(n)), ++n;
    return d[i];
  }
  mint operator[](int i) const { return d[i];}
} ifacts;
mint comb(int n, int k) {
  if (n < k || k < 0) return 0;
  return facts(n)*ifacts(k)*ifacts(n-k);
}

uint64_t combinations2(uint64_t n, uint64_t k) {
    uint64_t r = 1;
    for (uint64_t d = 1; d <= k; ++d) {
        r *= n--;
        r /= d;
    }
    return r;
}

// vector<vector<mint>> comb(n+1, vector<mint>(n+1));
// rep(i,n+1) comb[i][0] = 1;
// for(int i=1;i<=n;i++){
//     for(int j=1;j<=n;j++){
//         comb[i][j] = comb[i-1][j] + comb[i-1][j-1];
//     }
// }

//Lucasの定理(素数mod)
/* Com:nCk % p の計算のための構造体
    前処理・初期化: O(p^2)
    nCk(n,k): nCk % p の計算。O(log n)
*/
// struct Comb {
//     vector<vector<long long>> com;  // 前計算の結果を保存
//     long long p;                    // p は素数である必要がある
//     Comb(long long _p) : p(_p) {
//         init(p);
//     }
//     void init(long long p) {  // 動的計画法で前処理
//         com.assign(p, vector<long long>(p));
//         com[0][0] = 1;
//         for (int i = 1; i < p; i++) {
//             com[i][0] = 1;
//             for (int j = i; j > 0; j--) {
//                 com[i][j] = (com[i - 1][j - 1] + com[i - 1][j]) % p;
//             }
//         }
//     }
//     long long nCk(long long n, long long k) {
//         long long ret = 1;
//         while (n > 0) {  // 下から一桁ずつ計算する
//             int ni = n % p;
//             int ki = k % p;
//             ret *= com[ni][ki];
//             ret %= p;
//             n /= p;
//             k /= p;
//         }
//         return ret;
//     }
// };

int main()
{
    ll h, w, k;
    cin >> h >> w >> k;
    mint ans = 0;
    if(k==h*w){
        cout << 1 << endl;
        return 0;
    }
    for(int i=0;i<h;i++){
        ll cnt  = h * w - w * i - k;
        if(cnt%(h-i)==0){
            ll j = cnt/(h-i);
            dbg(i,j);
            ans += comb(h,i) * comb(w, j);
        }
    }
    cout << ans.val() << endl;
    return 0;
}
0