結果

問題 No.1145 Sums of Powers
コンテスト
ユーザー shkiiii_
提出日時 2026-09-21 21:11:34
言語 C++17
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
TLE  
実行時間 -
コード長 3,047 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,060 ms
コンパイル使用メモリ 292,860 KB
実行使用メモリ 28,492 KB
最終ジャッジ日時 2026-09-21 21:11:45
合計ジャッジ時間 9,147 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 3 TLE * 1 -- * 2
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<bits/stdc++.h>
#include<atcoder/all>
// #include<boost/multiprecision/cpp_int.hpp>

using namespace std;
using namespace atcoder;
// using bint = boost::multiprecision::cpp_int;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<ll>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using ve = vector<vector<int>>;
using vb = vector<bool>;
using vvb = vector<vb>;
// #define MOD 1000000007
#define MOD 998244353
// /*
using mint = atcoder::static_modint<MOD>;
using vm = vector<mint>;
using vvm = vector<vm>;
using vvvm = vector<vvm>;
ostream&operator<<(ostream&os,mint a){os<<a.val();return os;}
istream&operator>>(istream&is,mint&a){int x;is>>x;a=mint(x);return is;}
// */
#define rep(i,s,n) for(ll i = (ll)s;i < (ll)n;i++)
#define rrep(i,l,r) for(ll i = (r)-1;i >= l;i--)
#define ALL(x) (x).begin(),(x).end()
#define sz(c) ((ll)(c).size())
#define LB(A,x) (int)(lower_bound(A.begin(),A.end(),x)-A.begin())
#define UB(A,x) (int)(upper_bound(A.begin(),A.end(),x)-A.begin())
template<typename T>using min_priority_queue=priority_queue<T,vector<T>,greater<T>>;
template<typename T>ostream&operator<<(ostream&os,vector<T>&v){for(int i = 0;i < v.size();i++)os<<v[i]<<(i+1!=v.size()?" ":"");return os;}
template<typename T>istream&operator>>(istream&is,vector<T>&v){for(T&in:v)is>>in;return is;}
template<typename T1,typename T2>ostream&operator<<(ostream&os,pair<T1,T2>&p){os<<p.first<<" "<<p.second;return os;}
template<typename T1,typename T2>istream&operator>>(istream&is,pair<T1,T2>&p){is>>p.first>>p.second;return is;}
template<typename T> inline bool chmax(T &a,T b){if(a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a,T b){if(a > b){a = b;return true;}return false;}
ld dist(ld x1,ld y1,ld x2, ld y2){return sqrtl((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));}

// O(N logN)
vm inv(vm &f){
  assert(!f.empty() && f[0] != mint(0));
  int n = f.size();
  mint f_0 = f[0].inv();
  vm res(n);
  res[0] = f_0;
  rep(k,1,n){
    rep(i,0,k)res[k] += res[i]*f[k-i];
    res[k] *= -f_0;
  }
  return res;
}

int main(){
  
  ios_base::sync_with_stdio(0), cin.tie(0);
  ll n,m;cin >> n >> m;
  vector<pair<vm,vm>> f(n);
  min_priority_queue<pii> pq;
  rep(i,0,n){
    ll A;cin >> A;
    f[i].first = vm{1};
    f[i].second = vm{1,(MOD-A)%MOD};
    pq.push({sz(f[i].second),i});
  }
  while(sz(pq) >= 2){
    auto i = pq.top().second;pq.pop();
    auto j = pq.top().second;pq.pop();
    vm g = convolution(f[i].second,f[j].second);
    vm h = convolution(f[i].first,f[j].second);
    vm hh = convolution(f[i].second,f[j].first);
    if(sz(h) < sz(hh))swap(h,hh);
    rep(i,0,sz(hh))h[i] = h[i]+hh[i];
    if(sz(g) > m+1)g.resize(m+1);
    if(sz(h) > m+1)h.resize(m+1);
    swap(f[i].first,h);swap(f[i].second,g);
    pq.push({sz(f[i].second),i});
  }
  auto [g,gg] = f[pq.top().second];
  gg.resize(m+1);
  g = convolution(g,inv(gg));
  assert(sz(g) >= m);
  rep(i,1,m+1)cout << g[i] << " \n"[i+1 == m+1];

  
  return 0;
}
0