結果

問題 No.2111 Sum of Diff
ユーザー ぷらぷら
提出日時 2022-10-28 23:33:24
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 112 ms / 2,000 ms
コード長 643 bytes
コンパイル時間 2,520 ms
コンパイル使用メモリ 200,992 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-20 06:50:45
合計ジャッジ時間 5,041 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 111 ms
4,380 KB
testcase_03 AC 76 ms
4,380 KB
testcase_04 AC 16 ms
4,376 KB
testcase_05 AC 111 ms
4,380 KB
testcase_06 AC 112 ms
4,376 KB
testcase_07 AC 27 ms
4,376 KB
testcase_08 AC 37 ms
4,380 KB
testcase_09 AC 8 ms
4,380 KB
testcase_10 AC 11 ms
4,376 KB
testcase_11 AC 53 ms
4,376 KB
testcase_12 AC 52 ms
4,376 KB
testcase_13 AC 34 ms
4,380 KB
testcase_14 AC 90 ms
4,380 KB
testcase_15 AC 107 ms
4,376 KB
testcase_16 AC 46 ms
4,376 KB
testcase_17 AC 112 ms
4,380 KB
testcase_18 AC 34 ms
4,500 KB
testcase_19 AC 83 ms
4,380 KB
testcase_20 AC 111 ms
4,376 KB
testcase_21 AC 3 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

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