結果
問題 | No.2111 Sum of Diff |
ユーザー |
|
提出日時 | 2022-10-28 22:14:26 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 38 ms / 2,000 ms |
コード長 | 1,867 bytes |
コンパイル時間 | 2,001 ms |
コンパイル使用メモリ | 197,100 KB |
最終ジャッジ日時 | 2025-02-08 14:36:36 |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 20 |
ソースコード
#include <bits/stdc++.h>// clang-format offusing namespace std; using ll=long long; using ull=unsigned long long; using pll=pair<ll,ll>; const ll INF=4e18;void print0(){}; template<typename H,typename... T> void print0(H h,T... t){cout<<h;print0(t...);}void print(){print0("\n");}; template<typename H,typename... T>void print(H h,T... t){print0(h);if(sizeof...(T)>0)print0(" ");print(t...);}void perr0(){}; template<typename H,typename... T> void perr0(H h,T... t){cerr<<h;perr0(t...);}void perr(){perr0("\n");}; template<typename H,typename... T>void perr(H h,T... t){perr0(h);if(sizeof...(T)>0)perr0(" ");perr(t...);}void ioinit() { cout<<fixed<<setprecision(15); cerr<<fixed<<setprecision(6); ios_base::sync_with_stdio(0); cin.tie(0); }#define debug1(a) { cerr<<#a<<":"<<a<<endl; }#define debug2(a,b) { cerr<<#a<<":"<<a<<" "<<#b<<":"<<b<<endl; }#define debug3(a,b,c) { cerr<<#a<<":"<<a<<" "<<#b<<":"<<b<<" "<<#c<<":"<<c<<endl; }#define debug4(a,b,c,d) { cerr<<#a<<":"<<a<<" "<<#b<<":"<<b<<" "<<#c<<":"<<c<<" "<<#d<<":"<<d<<endl; }// clang-format onconst ll MODULO = 998244353;ll rangesum(ll l, ll r, vector<ll>& cum) {if (l == 0) return cum[r];return cum[r] - cum[l - 1];}int main() {// 一番左、一番右として選ばれる回数ioinit();ll N;cin >> N;vector<ll> A(N);for (ll i = 0; i < N; i++) {cin >> A[i];}vector<ll> cum(N, A[0]);for (ll i = 1; i < N; i++) {cum[i] = A[i] + cum[i - 1];}vector<ll> pow2(N + 1, 1);for (ll i = 1; i <= N; i++) {pow2[i] = pow2[i - 1] * 2 % MODULO;}ll ans = 0;for (ll i = 0; i < N; i++) {ll left = pow2[N - i - 1] - 1;ll right = pow2[i] - 1;ans += (left - right) * A[i] % MODULO;}ans %= MODULO;if (ans < 0) ans += MODULO;print(ans);return 0;}