結果
| 問題 |
No.3139 Interval MEX ?
|
| コンテスト | |
| ユーザー |
👑 potato167
|
| 提出日時 | 2025-05-02 18:10:43 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 107 ms / 2,000 ms |
| コード長 | 1,466 bytes |
| コンパイル時間 | 2,311 ms |
| コンパイル使用メモリ | 198,568 KB |
| 実行使用メモリ | 13,056 KB |
| 最終ジャッジ日時 | 2025-05-02 19:36:08 |
| 合計ジャッジ時間 | 11,151 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 57 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#include <atcoder/modint>
constexpr long long MOD = 998244353;
using mint = atcoder::modint998244353;
vector<mint> fact, invfact;
mint nPk(int n, int k) { // 0 <= k <= n
if (k < 0 || k > n) return 0;
return fact[n] * invfact[n - k];
}
mint count_geq(int N, int M, int x) {
if (x > N) return 0;
if (x == 0) // MEX >= 0
return fact[N + M - 1] * invfact[M - 1];
mint I;
if (x < M) { // x < M
I = nPk(N, x); // N_P^x
} else { // x >= M
I = fact[N - x + M - 1] * invfact[N - x];
I *= mint(N + M - x).pow(x - M + 1);
}
mint free = fact[N - x + M - 1] * invfact[M - 1];
return I * free;
}
vector<mint> solve(int N, int M) {
fact.resize(N + M + 1); invfact.resize(N + M + 1);
fact[0] = 1;
for (int i = 1; i <= N + M; ++i) fact[i] = fact[i - 1] * i;
invfact[N + M] = fact[N + M].inv();
for (int i = N + M; i >= 1; --i) invfact[i - 1] = invfact[i] * i;
vector<mint> ans(N + 1);
mint prev = count_geq(N, M, 0);
for (int x = 0; x <= N; ++x) {
mint cur = count_geq(N, M, x + 1);
ans[x] = prev - cur;
prev = cur;
}
return ans;
}
int main(){
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int N, M;
cin >> N >> M;
auto ans = solve(N, M);
for (auto x : ans) cout << x.val() << "\n";
}
potato167