結果
問題 | No.1510 Simple Integral |
ユーザー | oliverx3 |
提出日時 | 2021-04-11 11:21:00 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 49 ms / 2,000 ms |
コード長 | 7,674 bytes |
コンパイル時間 | 4,894 ms |
コンパイル使用メモリ | 282,524 KB |
実行使用メモリ | 6,948 KB |
最終ジャッジ日時 | 2024-09-14 22:56:51 |
合計ジャッジ時間 | 6,867 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge6 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,812 KB |
testcase_02 | AC | 2 ms
6,816 KB |
testcase_03 | AC | 2 ms
6,940 KB |
testcase_04 | AC | 2 ms
6,944 KB |
testcase_05 | AC | 2 ms
6,940 KB |
testcase_06 | AC | 49 ms
6,944 KB |
testcase_07 | AC | 49 ms
6,944 KB |
testcase_08 | AC | 48 ms
6,940 KB |
testcase_09 | AC | 48 ms
6,940 KB |
testcase_10 | AC | 48 ms
6,940 KB |
testcase_11 | AC | 49 ms
6,944 KB |
testcase_12 | AC | 49 ms
6,940 KB |
testcase_13 | AC | 2 ms
6,940 KB |
testcase_14 | AC | 3 ms
6,944 KB |
testcase_15 | AC | 2 ms
6,940 KB |
testcase_16 | AC | 2 ms
6,940 KB |
testcase_17 | AC | 2 ms
6,940 KB |
testcase_18 | AC | 2 ms
6,940 KB |
testcase_19 | AC | 2 ms
6,940 KB |
testcase_20 | AC | 2 ms
6,944 KB |
testcase_21 | AC | 3 ms
6,948 KB |
testcase_22 | AC | 2 ms
6,940 KB |
testcase_23 | AC | 2 ms
6,940 KB |
testcase_24 | AC | 3 ms
6,940 KB |
testcase_25 | AC | 3 ms
6,944 KB |
testcase_26 | AC | 3 ms
6,940 KB |
testcase_27 | AC | 3 ms
6,940 KB |
testcase_28 | AC | 2 ms
6,944 KB |
testcase_29 | AC | 3 ms
6,940 KB |
testcase_30 | AC | 3 ms
6,944 KB |
testcase_31 | AC | 3 ms
6,940 KB |
testcase_32 | AC | 3 ms
6,940 KB |
testcase_33 | AC | 3 ms
6,944 KB |
testcase_34 | AC | 3 ms
6,940 KB |
testcase_35 | AC | 2 ms
6,940 KB |
testcase_36 | AC | 3 ms
6,940 KB |
testcase_37 | AC | 2 ms
6,944 KB |
testcase_38 | AC | 2 ms
6,948 KB |
testcase_39 | AC | 3 ms
6,940 KB |
testcase_40 | AC | 3 ms
6,944 KB |
testcase_41 | AC | 2 ms
6,940 KB |
testcase_42 | AC | 2 ms
6,940 KB |
testcase_43 | AC | 2 ms
6,940 KB |
testcase_44 | AC | 2 ms
6,944 KB |
testcase_45 | AC | 3 ms
6,940 KB |
ソースコード
#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::vector<long long> a,c; { std::map<int,int> mp; for(const auto &p:v) mp[p]++; for(const auto &p:mp) a.push_back(p.first),c.push_back(p.second); } n = a.size(); 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; }