結果

問題 No.1866 Unfair Tournament
ユーザー shiomusubi496shiomusubi496
提出日時 2022-03-03 23:15:02
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 761 ms / 3,000 ms
コード長 2,599 bytes
コンパイル時間 4,920 ms
コンパイル使用メモリ 273,744 KB
実行使用メモリ 16,692 KB
最終ジャッジ日時 2023-09-25 21:20:01
合計ジャッジ時間 11,110 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 7 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 12 ms
4,376 KB
testcase_10 AC 4 ms
4,380 KB
testcase_11 AC 3 ms
4,380 KB
testcase_12 AC 748 ms
16,480 KB
testcase_13 AC 749 ms
16,580 KB
testcase_14 AC 761 ms
16,580 KB
testcase_15 AC 760 ms
16,620 KB
testcase_16 AC 760 ms
16,692 KB
testcase_17 AC 760 ms
16,528 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>

using namespace std;

template<class T> class Combinatorics {
  private:
    static vector<T> factorial;
    static vector<T> factinv;
  public:
    static void init(int n) {
        int b = factorial.size();
        if (n < b) return;
        factorial.reserve(n + 1);
        while ((int)factorial.size() <= n) factorial.push_back(factorial.back() * factorial.size());
        factinv.resize(n + 1);
        factinv[n] = T(1) / factorial[n];
        for (int i = n; i > b; --i) factinv[i - 1] = factinv[i] * i;
    }
    static T fact(int x) {
        init(x);
        return factorial[x];
    }
    static T finv(int x) {
        init(x);
        return factinv[x];
    }
    static T comb(int n, int r) {
        if (r < 0 || r > n) return 0;
        init(n);
        return factorial[n] * factinv[n - r] * factinv[r];
    }
};

template<class T> std::vector<T> Combinatorics<T>::factorial = std::vector<T>(1, 1);
template<class T> std::vector<T> Combinatorics<T>::factinv = std::vector<T>(1, 1);

using mint = atcoder::modint998244353;
using comb = Combinatorics<mint>;

int main() {
    int N, A, B; cin >> N >> A >> B;
    mint T = mint{A} / mint{B};
    vector<vector<mint>> f(N + 1);
    f[0] = {0, 1};
    for (int i = 0; i < N; ++i) {
        int M = 1 << i;
        vector<mint> a = f[i];
        vector<mint> b(M + 1);
        for (int j = 0; j <= M; ++j) b[j] = 1 - a[j];
        for (int j = 0; j <= M; ++j) a[j] *= comb::comb(M, j);
        for (int j = 0; j <= M; ++j) b[j] *= comb::comb(M, j);
        vector<mint> c = atcoder::convolution(a, a);
        vector<mint> d = atcoder::convolution(a, b);
        vector<mint> e = atcoder::convolution(b, a);
        f[i + 1].resize(M * 2 + 1);
        for (int j = 0; j <= M * 2; ++j) {
            f[i + 1][j] = c[j] + T * (d[j] + e[j]);
            f[i + 1][j] /= comb::comb(M * 2, j);
        }
    }
    vector<vector<mint>> g(N + 1);
    g[0] = {1};
    for (int i = 0; i < N; ++i) {
        int M = 1 << i;
        vector<mint> a = g[i];
        vector<mint> b(M + 1);
        for (int j = 0; j <= M; ++j) b[j] = (1 - T) * f[i][j] + T * (1 - f[i][j]);
        for (int j = 0; j < M; ++j) a[j] *= comb::comb(M - 1, j);
        for (int j = 0; j <= M; ++j) b[j] *= comb::comb(M, j);
        vector<mint> c = atcoder::convolution(a, b);
        g[i + 1].resize(M * 2);
        for (int j = 0; j < M * 2; ++j) {
            g[i + 1][j] = c[j];
            g[i + 1][j] /= comb::comb(M * 2 - 1, j);
        }
    }
    for (int i = 0; i < (1 << N); ++i) cout << g[N][i].val() << endl;
}
0