結果

問題 No.2111 Sum of Diff
ユーザー nyyanyya
提出日時 2022-12-17 18:09:41
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 86 ms / 2,000 ms
コード長 1,308 bytes
コンパイル時間 4,095 ms
コンパイル使用メモリ 231,292 KB
実行使用メモリ 5,632 KB
最終ジャッジ日時 2024-04-28 11:58:08
合計ジャッジ時間 6,646 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
5,248 KB
testcase_01 AC 4 ms
5,376 KB
testcase_02 AC 83 ms
5,632 KB
testcase_03 AC 58 ms
5,376 KB
testcase_04 AC 15 ms
5,376 KB
testcase_05 AC 84 ms
5,632 KB
testcase_06 AC 83 ms
5,504 KB
testcase_07 AC 24 ms
5,376 KB
testcase_08 AC 31 ms
5,376 KB
testcase_09 AC 9 ms
5,376 KB
testcase_10 AC 11 ms
5,376 KB
testcase_11 AC 42 ms
5,376 KB
testcase_12 AC 41 ms
5,376 KB
testcase_13 AC 28 ms
5,376 KB
testcase_14 AC 69 ms
5,504 KB
testcase_15 AC 80 ms
5,504 KB
testcase_16 AC 36 ms
5,376 KB
testcase_17 AC 86 ms
5,504 KB
testcase_18 AC 29 ms
5,376 KB
testcase_19 AC 64 ms
5,376 KB
testcase_20 AC 84 ms
5,504 KB
testcase_21 AC 5 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i,n) for(int i=0;i<(n);i++)
#define per(i,n) for(int i=(n)-1;i>=0;i--)
#define all(x) x.begin(),x.end()
typedef long long ll;
//using mint = modint;
using mint = modint998244353;
//using mint = modint1000000007;
using P = pair<int, int>;

const ll INF=1LL<<60, dx[]={0,1,0,-1},dy[]={1,0,-1,0};
template <typename T> inline bool chmin(T& a,const T&b) {if(a>b){a=b; return 1;} return 0;}
template <typename T> inline bool chmax(T& a,const T&b) {if(a<b){a=b; return 1;} return 0;}

int main(){

    int n;
    cin >> n;

    vector<mint> a(n);
    rep(i,n) {ll t;cin >> t;a[i]=t;}

    mint pow2[200001];
    mint sum_pow2[200002];
    pow2[0]=1;
    sum_pow2[0]=0;
    rep(i,200000) pow2[i+1]=pow2[i]*2;
    rep(i,200001) sum_pow2[i+1]=sum_pow2[i]+pow2[i];

    auto get_pw2=[&](int l,int r) -> mint {
        return sum_pow2[r]-sum_pow2[l];
    };

    mint ans=0;
    for(int i=0;i<n;i++) {
        int l=i,r=n-1-i;

        ans += a[i] * get_pw2(l,r);
    }

    /*
    for(int k=1;k<n;k++) {
        for(int i=0;i<min(n-k,k);i++) {
            int p=(n-1-i)/k;
            int r=i+k*p;
            ans+= (a[i]-a[r])*pow2[n-k-1];
        }
    }
    */
    cout << ans.val() << endl;

    return 0;

}
0