結果
問題 | No.2111 Sum of Diff |
ユーザー |
![]() |
提出日時 | 2022-10-28 22:16:10 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 86 ms / 2,000 ms |
コード長 | 895 bytes |
コンパイル時間 | 1,730 ms |
コンパイル使用メモリ | 194,868 KB |
最終ジャッジ日時 | 2025-02-08 14:37:57 |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 20 |
ソースコード
#include<bits/stdc++.h> using namespace std; #define rep(i,n) for (long long i=0;i<(long long)(n);i++) #define all(v) v.begin(),v.end() using ll=long long; using pll=pair<ll,ll>; using tll=tuple<ll,ll,ll>; const ll INF=(1ll<<60); template<class T> void chmin(T &a,T b){ if(a>b){ a=b; } } template<class T> void chmax(T &a,T b){ if(a<b){ a=b; } } int main(){ const ll mod=998244353; ll n; cin >> n; vector<ll> a(n); rep(i,n) cin >> a[i]; vector<ll> r(n+1); r[0]=1; rep(i,n) r[i+1]=r[i]*2%mod; ll sum=0; vector<ll> v(n); rep(i,n-1){ sum+=r[i]; sum%=mod; } v[0]=sum; rep(i,n-1) v[i+1]=(v[i]-r[i]+mod)%mod; ll ans=0; rep(i,n){ ans+=a[i]*v[i]%mod; ans%=mod; } reverse(all(v)); rep(i,n){ ans=(ans-a[i]*v[i]%mod+mod)%mod; } cout << ans << endl; }