結果
| 問題 |
No.1866 Unfair Tournament
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-03-03 23:52:51 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 593 ms / 3,000 ms |
| コード長 | 2,320 bytes |
| コンパイル時間 | 4,681 ms |
| コンパイル使用メモリ | 263,316 KB |
| 最終ジャッジ日時 | 2025-01-28 04:35:03 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 15 |
ソースコード
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using Fp = modint998244353;
#define REP_2(i, n) for (int i = 0; i < (n); ++i)
#define REP_3(i, l, r) for (int i = (l); i < (r); ++i)
template <int S> struct mint_data {
static inline array<Fp, S + 1> fact, inv, inv_fact;
static void build() {
fact[0] = fact[1] = inv[1] = inv_fact[0] = inv_fact[1] = 1;
REP_3(i, 2, S + 1) {
fact[i] = fact[i - 1] * i;
inv[i] = -(Fp::mod() / i) * inv[Fp::mod() % i];
inv_fact[i] = inv_fact[i - 1] * inv[i];
}
}
static Fp comb(const int n, const int k) {
assert(0 <= k and k <= n and n <= S);
return fact[n] * inv_fact[n - k] * inv_fact[k];
}
};
using combd = mint_data<1000000>;
int read() {
int ret;
cin >> ret;
return ret;
}
void out(const int n) {
cout << n << endl;
return;
}
int main() {
const int N = read();
const int A = read();
const int B = read();
const Fp T = Fp(A) / Fp(B);
combd::build();
vector<vector<Fp>> f(N);
f[0] = {0, 1};
REP_2(d, N - 1) {
const int m = 1 << d;
assert((int)f[d].size() == m + 1);
auto a = f[d];
vector<Fp> rz(m + 1);
REP_2(i, m + 1) rz[i] = 1 - a[i];
REP_2(i, m + 1) {
a[i] *= combd::comb(m, i);
rz[i] *= combd::comb(m, i);
}
auto cvd1 = convolution<Fp>(a, a);
auto cvd2 = convolution<Fp>(a, rz);
f[d + 1].resize(2 * m + 1);
REP_2(i, 2 * m + 1) {
f[d + 1][i] = cvd1[i] + T * (2 * cvd2[i]);
f[d + 1][i] /= combd::comb(2 * m, i);
}
}
vector<vector<Fp>> g(N + 1);
g[0] = {1};
REP_2(d, N) {
const int m = 1 << d;
assert((int)g[d].size() == m);
auto a = g[d];
vector<Fp> rz(m + 1);
REP_2(i, m + 1) rz[i] = (1 - T) * f[d][i] + T * (1 - f[d][i]);
REP_2(i, m) a[i] *= combd::comb(m - 1, i);
REP_2(i, m + 1) rz[i] *= combd::comb(m, i);
auto cvd = convolution<Fp>(a, rz);
g[d + 1].resize(2 * m);
REP_2(i, 2 * m) {
g[d + 1][i] = cvd[i];
g[d + 1][i] /= combd::comb(2 * m - 1, i);
}
}
for (const Fp e : g[N]) out(e.val());
}