結果

問題 No.1510 Simple Integral
ユーザー oliverx3oliverx3
提出日時 2021-04-10 16:01:11
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 7,621 bytes
コンパイル時間 4,752 ms
コンパイル使用メモリ 277,024 KB
実行使用メモリ 8,696 KB
最終ジャッジ日時 2023-10-13 01:10:12
合計ジャッジ時間 10,476 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,908 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 2 ms
4,352 KB
testcase_03 AC 1 ms
4,352 KB
testcase_04 WA -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define drep(i, n) for(int i = (int)(n)-1; i >= 0; i--)

template<class T>
struct FormalPowerSeries : std::vector<T> {
    
    using std::vector<T>::vector;
    using std::vector<T>::operator=;
    using F = FormalPowerSeries;

    F operator-() const {
        F res(*this);
        for (auto &e : res) e = -e;
        return res;
    }
    F &operator*=(const T &g) {
        for (auto &e : *this) e *= g;
        return *this;
    }
    F &operator/=(const T &g) {
        assert(g != T(0));
        *this *= g.inv();
        return *this;
    }
    F &operator+=(const F &g) {
        int n = (*this).size(), m = g.size();
        rep(i, std::min(n, m)) (*this)[i] += g[i];
        return *this;
    }
    F &operator-=(const F &g) {
        int n = (*this).size(), m = g.size();
        rep(i, std::min(n, m)) (*this)[i] -= g[i];
        return *this;
    }
    F &operator<<=(const int d) {
        int n = (*this).size();
        (*this).insert((*this).begin(), d, 0);
        (*this).resize(n);
        return *this;
    }
    F &operator>>=(const int d) {
        int n = (*this).size();
        (*this).erase((*this).begin(), (*this).begin() + std::min(n, d));
        (*this).resize(n);
        return *this;
    }
    F inv(int d = -1) const {
        int n = (*this).size();
        assert(n != 0 && (*this)[0] != 0);
        if (d == -1) d = n;
        assert(d > 0);
        F res{(*this)[0].inv()};
        while (res.size() < d) {
        int m = size(res);
        F f(begin(*this), begin(*this) + std::min(n, 2*m));
        F r(res);
        f.resize(2*m), atcoder::internal::butterfly(f);
        r.resize(2*m), atcoder::internal::butterfly(r);
        rep(i, 2*m) f[i] *= r[i];
        atcoder::internal::butterfly_inv(f);
        f.erase(f.begin(), f.begin() + m);
        f.resize(2*m), atcoder::internal::butterfly(f);
        rep(i, 2*m) f[i] *= r[i];
        atcoder::internal::butterfly_inv(f);
        T iz = T(2*m).inv(); iz *= -iz;
        rep(i, m) f[i] *= iz;
        res.insert(res.end(), f.begin(), f.begin() + m);
        }
        return {res.begin(), res.begin() + d};
    }

    // fast: FMT-friendly modulus only
    F &operator*=(const F &g) {
      int n = (*this).size();
      *this = convolution(*this, g);
      (*this).resize(n);
      return *this;
    }
    F &operator/=(const F &g) {
      int n = (*this).size();
      *this = convolution(*this, g.inv(n));
      (*this).resize(n);
      return *this;
    }

    // // naive
    // F &operator*=(const F &g) {
    //   int n = (*this).size(), m = g.size();
    //   drep(i, n) {
    //     (*this)[i] *= g[0];
    //     REP(j, 1, std::min(i+1, m)) (*this)[i] += (*this)[i-j] * g[j];
    //   }
    //   return *this;
    // }
    // F &operator/=(const F &g) {
    //   assert(g[0] != T(0));
    //   T ig0 = g[0].inv();
    //   int n = (*this).size(), m = g.size();
    //   rep(i, n) {
    //     REP(j, 1, std::min(i+1, m)) (*this)[i] -= (*this)[i-j] * g[j];
    //     (*this)[i] *= ig0;
    //   }
    //   return *this;
    // }

    // sparse
    F &operator*=(std::vector<std::pair<int, T>> g) {
        int n = (*this).size();
        auto [d, c] = g.front();
        if (d == 0) g.erase(g.begin());
        else c = 0;
        drep(i, n) {
        (*this)[i] *= c;
        for (auto &[j, b] : g) {
            if (j > i) break;
            (*this)[i] += (*this)[i-j] * b;
        }
        }
        return *this;
    }
    F &operator/=(std::vector<std::pair<int, T>> g) {
        int n = (*this).size();
        auto [d, c] = g.front();
        assert(d == 0 && c != T(0));
        T ic = c.inv();
        g.erase(g.begin());
        rep(i, n) {
        for (auto &[j, b] : g) {
            if (j > i) break;
            (*this)[i] -= (*this)[i-j] * b;
        }
        (*this)[i] *= ic;
        }
        return *this;
    }

    // multiply and divide (1 + cz^d)
    void multiply(const int d, const T c) { 
        int n = (*this).size();
        if (c == T(1)) drep(i, n-d) (*this)[i+d] += (*this)[i];
        else if (c == T(-1)) drep(i, n-d) (*this)[i+d] -= (*this)[i];
        else drep(i, n-d) (*this)[i+d] += (*this)[i] * c;
    }
    void divide(const int d, const T c) {
        int n = (*this).size();
        if (c == T(1)) rep(i, n-d) (*this)[i+d] -= (*this)[i];
        else if (c == T(-1)) rep(i, n-d) (*this)[i+d] += (*this)[i];
        else rep(i, n-d) (*this)[i+d] -= (*this)[i] * c;
    }

    T eval(const T &a) const {
        T x(1), res(0);
        for (auto e : *this) res += e * x, x *= a;
        return res;
    }

    F operator*(const T &g) const { return F(*this) *= g; }
    F operator/(const T &g) const { return F(*this) /= g; }
    F operator+(const F &g) const { return F(*this) += g; }
    F operator-(const F &g) const { return F(*this) -= g; }
    F operator<<(const int d) const { return F(*this) <<= d; }
    F operator>>(const int d) const { return F(*this) >>= d; }
    F operator*(const F &g) const { return F(*this) *= g; }
    F operator/(const F &g) const { return F(*this) /= g; }
    F operator*(std::vector<std::pair<int, T>> g) const { return F(*this) *= g; }
    F operator/(std::vector<std::pair<int, T>> g) const { return F(*this) /= g; }
};

using mint = atcoder::modint998244353;
using fps = FormalPowerSeries<mint>;
using sfps = std::vector<std::pair<int,mint>>;

constexpr int MAX = 2010;
constexpr int MOD = 998244353;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    COMinit();

    int n;
    std::cin >> n;

    std::vector<int> v(n);
    rep(i, n) std::cin >> v[i];
    
    std::map<int,int> mp;
    for(const auto &p:v) mp[p]++;

    std::vector<int> a,c;
    for(const auto &p:mp) a.push_back(p.first),c.push_back(p.second);

    mint final_ans = 0;

    rep(i, n) {
        fps f;
        f.resize(c[i]);
        f[0] = 1;
        {//最初の式
            fps Y;
            Y.resize(2);
            Y[1] = 1;
            fps sub_f;
            sub_f.resize(c[i]);
            sub_f[0] = 1;
            rep(k, n) {
                if(i==k) continue;
                rep(_j, c[k]) {
                    Y[0] = a[k]*a[k]-a[i]*a[i];
                    sub_f *= Y;
                }
            }
            f*=sub_f;
        }

        mint A = f[0];
        
        fps g = f;
        g[0] = 0;
        
        rep(j, c[i]) f[j] = 0;

        rep(k, c[i]) {//2番目の式
            fps sub_f;
            sub_f.resize(c[i]);
            sub_f[0] = 1;
            rep(_j, k) {
                sub_f*=g;
                sub_f/=A;
                sub_f*=-1;
            }
            f+=sub_f;
        }

        std::vector<mint> p(c[i]);
        rep(j, c[i]) p[j] = f[j];


        mint ans = 0;
        rep(j, c[i]) {
            mint x;
            x = COM(2*c[i]-2*j,c[i]-j)*(c[i]-j)*p[j];
            mint a_i = a[i];
            x /= (2*a_i).pow(2*c[i]-2*j) * (2*c[i]-2*j-1);
            ans+=x;
        }
        ans*=2*a[i];
        ans/=A;
        
        final_ans+=ans;
    }

    std::cout << final_ans.val() << std::endl;
    return 0;
}
0