結果

問題 No.2111 Sum of Diff
ユーザー butsurizukibutsurizuki
提出日時 2022-10-28 21:31:08
言語 C++23(draft)
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 64 ms / 2,000 ms
コード長 713 bytes
コンパイル時間 3,249 ms
コンパイル使用メモリ 244,580 KB
実行使用メモリ 4,688 KB
最終ジャッジ日時 2023-09-20 04:17:06
合計ジャッジ時間 5,402 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 64 ms
4,520 KB
testcase_03 AC 43 ms
4,376 KB
testcase_04 AC 10 ms
4,376 KB
testcase_05 AC 63 ms
4,560 KB
testcase_06 AC 63 ms
4,616 KB
testcase_07 AC 16 ms
4,376 KB
testcase_08 AC 21 ms
4,380 KB
testcase_09 AC 5 ms
4,380 KB
testcase_10 AC 7 ms
4,376 KB
testcase_11 AC 30 ms
4,376 KB
testcase_12 AC 29 ms
4,376 KB
testcase_13 AC 19 ms
4,380 KB
testcase_14 AC 52 ms
4,380 KB
testcase_15 AC 61 ms
4,448 KB
testcase_16 AC 26 ms
4,380 KB
testcase_17 AC 63 ms
4,428 KB
testcase_18 AC 19 ms
4,376 KB
testcase_19 AC 47 ms
4,380 KB
testcase_20 AC 63 ms
4,688 KB
testcase_21 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define mod 998244353

using 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;
}
0