結果
| 問題 | No.1388 Less than K |
| コンテスト | |
| ユーザー |
vjudge1
|
| 提出日時 | 2026-04-18 12:16:59 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 9 ms / 3,000 ms |
| コード長 | 2,137 bytes |
| 記録 | |
| コンパイル時間 | 1,275 ms |
| コンパイル使用メモリ | 170,140 KB |
| 実行使用メモリ | 9,728 KB |
| 最終ジャッジ日時 | 2026-04-18 12:17:04 |
| 合計ジャッジ時間 | 3,366 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 74 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const long long MOD = 998244353;
// ???
long long mod_pow(long long a, long long e) {
long long r = 1;
a %= MOD;
while (e) {
if (e & 1) r = r * a % MOD;
a = a * a % MOD;
e >>= 1;
}
return r;
}
// ?????????
struct Comb {
vector<long long> fac, ifac;
Comb(int n) {
fac.assign(n + 1, 1);
ifac.assign(n + 1, 1);
for (int i = 1; i <= n; ++i) fac[i] = fac[i - 1] * i % MOD;
ifac[n] = mod_pow(fac[n], MOD - 2);
for (int i = n; i >= 1; --i) ifac[i - 1] = ifac[i] * i % MOD;
}
long long C(int n, int k) {
if (k < 0 || k > n) return 0;
return fac[n] * ifac[k] % MOD * ifac[n - k] % MOD;
}
};
int main() {
// ??????
ios::sync_with_stdio(false);
cin.tie(nullptr);
long long H, W, K;
if (!(cin >> H >> W >> K)) return 0;
int h = H - 1;
int w = W - 1;
int N = h + w;
int d = K / 2;
Comb comb(N);
// ??1????????0 => ????????
if (d == 0) {
cout << comb.C(N, h) << '\n';
return 0;
}
// ??2????????? => ????????
if (d >= min(h, w)) {
long long all = comb.C(N, h);
cout << all * all % MOD << '\n';
return 0;
}
long long ans = 0;
int period = 2 * d + 2;
// ????? X_1 = k * period????????????????? -N/period ? N/period
int kmin = -N / period - 2;
int kmax = N / period + 2;
// O(N/d) ???????
for (int k = kmin; k <= kmax; ++k) {
// ????? (????)
long long X1 = 1LL * k * period;
if (h + X1 >= 0 && h + X1 <= N && w + X1 >= 0 && w + X1 <= N) {
long long term = comb.C(N, h + X1) * comb.C(N, w + X1) % MOD;
ans = (ans + term) % MOD;
}
// ????? (????)
long long X2 = d + 1 + 1LL * k * period;
if (h + X2 >= 0 && h + X2 <= N && w + X2 >= 0 && w + X2 <= N) {
long long term = comb.C(N, h + X2) * comb.C(N, w + X2) % MOD;
ans = (ans - term + MOD) % MOD;
}
}
cout << ans << '\n';
return 0;
}
vjudge1