結果

問題 No.2111 Sum of Diff
ユーザー CleyLCleyL
提出日時 2022-12-21 01:15:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 84 ms / 2,000 ms
コード長 602 bytes
コンパイル時間 664 ms
コンパイル使用メモリ 73,728 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2024-04-29 03:06:40
合計ジャッジ時間 2,514 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 84 ms
6,400 KB
testcase_03 AC 58 ms
5,376 KB
testcase_04 AC 13 ms
5,376 KB
testcase_05 AC 84 ms
6,400 KB
testcase_06 AC 84 ms
6,400 KB
testcase_07 AC 22 ms
5,376 KB
testcase_08 AC 30 ms
5,376 KB
testcase_09 AC 7 ms
5,376 KB
testcase_10 AC 9 ms
5,376 KB
testcase_11 AC 41 ms
5,376 KB
testcase_12 AC 40 ms
5,376 KB
testcase_13 AC 27 ms
5,376 KB
testcase_14 AC 70 ms
5,760 KB
testcase_15 AC 81 ms
6,400 KB
testcase_16 AC 35 ms
5,376 KB
testcase_17 AC 84 ms
6,400 KB
testcase_18 AC 27 ms
5,376 KB
testcase_19 AC 65 ms
5,632 KB
testcase_20 AC 84 ms
6,400 KB
testcase_21 AC 3 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;
const long long mod = 998244353;
int main(){
  int n;cin>>n;
  vector<long long> A(n);
  for(int i = 0; n > i; i++)cin>>A[i];
  vector<long long> B(n-1);
  long long sm = 0;
  for(int i = 0; n-1 > i; i++){
    B[i] = A[i]-A[i+1];
    sm = (sm + B[i])%mod;
  }
  long long tmp = sm;
  long long width = sm;
  long long nw = 1;
  long long ans = 0;
  for(int i = 0; n-1 > i; i++){
    ans = (ans + width * nw + mod)%mod;
    tmp = (tmp - (B[i]+B[n-2-i]) + mod)%mod;
    width = (width+tmp)%mod;
    nw = (nw*2)%mod;
  }
  cout << ans << endl;
}
0