結果
| 問題 |
No.1510 Simple Integral
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-04-10 16:03:00 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 7,647 bytes |
| コンパイル時間 | 8,097 ms |
| コンパイル使用メモリ | 267,936 KB |
| 最終ジャッジ日時 | 2025-01-20 15:46:38 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 12 RE * 11 TLE * 20 |
ソースコード
#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);
}
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;
}