結果
問題 | No.2817 Competition |
ユーザー |
|
提出日時 | 2024-07-18 02:26:17 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 817 ms / 2,000 ms |
コード長 | 2,282 bytes |
コンパイル時間 | 2,152 ms |
コンパイル使用メモリ | 210,952 KB |
最終ジャッジ日時 | 2025-02-23 16:08:39 |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 24 |
ソースコード
#include <bits/stdc++.h> #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") using namespace std; using ll = long long; const ll mod = 998244353; #define fi first #define se second #define rep(i,n) for(ll i=0;i<n;i++) #define all(x) x.begin(),x.end() #define faster ios::sync_with_stdio(false);cin.tie(nullptr) const ll root = 3; ll modpow(ll A,ll N){ ll res=1; while(N){ if(N&1) res=res*A%mod; A=A*A%mod; N>>=1; } return res; } ll modinv(ll A){return modpow(A,mod-2);} void NTT(vector<ll> &A,const bool rev=false){ vector<ll> B(A.size(),0); ll R=mod-1-(mod-1)/((ll)A.size()); if(rev) R=(mod-1)/((ll)A.size()); ll s=modpow(root,R); vector<ll> power((ll)A.size()/2+1,1); rep(i,(ll)A.size()/2) power[i+1]=(power[i]*s)%mod; ll cur=(ll)A.size()/2; for(ll i=1;i<(ll)A.size();i*=2){ rep(j,cur){ rep(k,i){ ll p=A[k+i*j]; ll q=A[k+i*j+(ll)A.size()/2]; B[k+2*i*j]=(p+q)%mod; B[k+2*i*j+i]=(p+mod-q)*power[i*j]%mod; } } swap(A,B); cur/=2; } if(rev){ s=modinv((ll)A.size()); rep(i,(ll)A.size()) A[i]=(A[i]*s)%mod; } } vector<ll> convolution(vector<ll> A,vector<ll> B){ ll size_=1; while(size_<=(ll)A.size()+(ll)B.size()-1) size_*=2; while(A.size()<size_) A.push_back(0); while(B.size()<size_) B.push_back(0); NTT(A); NTT(B); rep(i,size_) A[i]=(A[i]*B[i])%mod; NTT(A,true); return A; } vector<ll> mult(vector<ll> A,vector<ll> B,ll deg){ vector<ll> ans=convolution(A,B); if(ans.size()<deg) ans.push_back(0); vector<ll> ANS(deg); rep(i,deg) ANS[i]=ans[i]; return ANS; } int main() { ll N; cin >> N; deque<vector<ll>> que; rep(i,N){ ll a; cin >> a; que.push_back({1,a%mod}); } while(que.size()>=2){ auto q1=que.front(); que.pop_front(); auto q2=que.front(); que.pop_front(); que.push_back(mult(q1,q2,q1.size()+q2.size()-1)); } vector<ll> A=que.front(); ll ans=0; rep(i,N){ ans+=modpow(N-i,i)*A[N-i]; ans%=mod; } cout << ans << endl; return 0; }