結果

問題 No.2111 Sum of Diff
ユーザー FplusFplusFFplusFplusF
提出日時 2022-10-28 22:16:10
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 84 ms / 2,000 ms
コード長 895 bytes
コンパイル時間 2,128 ms
コンパイル使用メモリ 200,548 KB
実行使用メモリ 7,992 KB
最終ジャッジ日時 2023-09-20 05:17:28
合計ジャッジ時間 4,522 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 84 ms
7,992 KB
testcase_03 AC 57 ms
6,132 KB
testcase_04 AC 13 ms
4,376 KB
testcase_05 AC 83 ms
7,760 KB
testcase_06 AC 84 ms
7,740 KB
testcase_07 AC 21 ms
4,376 KB
testcase_08 AC 29 ms
4,572 KB
testcase_09 AC 7 ms
4,380 KB
testcase_10 AC 9 ms
4,380 KB
testcase_11 AC 41 ms
5,072 KB
testcase_12 AC 39 ms
5,240 KB
testcase_13 AC 26 ms
4,376 KB
testcase_14 AC 69 ms
6,748 KB
testcase_15 AC 80 ms
7,492 KB
testcase_16 AC 35 ms
4,976 KB
testcase_17 AC 84 ms
7,784 KB
testcase_18 AC 27 ms
4,380 KB
testcase_19 AC 64 ms
6,496 KB
testcase_20 AC 83 ms
7,784 KB
testcase_21 AC 3 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0