結果

問題 No.2111 Sum of Diff
ユーザー ぷら
提出日時 2022-10-28 23:33:24
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 154 ms / 2,000 ms
コード長 643 bytes
コンパイル時間 1,967 ms
コンパイル使用メモリ 194,656 KB
最終ジャッジ日時 2025-02-08 15:16:53
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

constexpr int mod = 998244353;

long long modpow(long long a,long long b) {
    long long ans = 1;
    while(b) {
        if(b & 1) {
            (ans *= a) %= mod;
        }
        (a *= a) %= mod;
        b /= 2;
    }
    return ans;
}

int main() {
    int N;
    cin >> N;
    vector<int>a(N);
    for(int i = 0; i < N; i++) {
        cin >> a[i];
    }
    int ans = 0;
    for(int i = 0; i < N; i++) {
        ans += a[i]*modpow(2,N-i-1)%mod;
        if(ans >= mod) ans -= mod;
        ans += (mod-a[i])*modpow(2,i)%mod;
        if(ans >= mod) ans -= mod;
    }
    cout << ans << endl;
}
0