結果
問題 | No.2111 Sum of Diff |
ユーザー |
|
提出日時 | 2022-10-28 21:31:08 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 62 ms / 2,000 ms |
コード長 | 713 bytes |
コンパイル時間 | 3,169 ms |
コンパイル使用メモリ | 246,768 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-06 00:33:18 |
合計ジャッジ時間 | 5,051 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 20 |
ソースコード
#include<bits/stdc++.h>#define mod 998244353using namespace std;long long power(long long a,long long b){long long x=1,y=a;while(b>0){if(b&1ll){x=(x*y)%mod;}y=(y*y)%mod;b>>=1;}return x%mod;}int main(){ios::sync_with_stdio(false);cin.tie(nullptr);long long n;cin >> n;vector<long long> a(n);for(auto &nx : a){cin >> nx;}long long pref=a[0],pc=1,res=0;for(long long i=1;i<n;i++){long long del=(a[i]*pc)%mod;del+=mod;del-=pref;del%=mod;del*=power(2,n-i-1);del%=mod;res+=del;res%=mod;pref+=a[i]*power(2,i);pref%=mod;pc+=power(2,i);pc%=mod;}res*=(mod-1);res%=mod;cout << res << "\n";return 0;}