結果

問題 No.2717 Sum of Subarray of Subsequence
ユーザー hongrockhongrock
提出日時 2024-04-05 22:36:07
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 29 ms / 2,000 ms
コード長 866 bytes
コンパイル時間 2,267 ms
コンパイル使用メモリ 201,780 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-04-05 22:36:20
合計ジャッジ時間 3,378 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 1 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 29 ms
6,676 KB
testcase_10 AC 29 ms
6,676 KB
testcase_11 AC 28 ms
6,676 KB
testcase_12 AC 28 ms
6,676 KB
testcase_13 AC 28 ms
6,676 KB
testcase_14 AC 28 ms
6,676 KB
testcase_15 AC 28 ms
6,676 KB
testcase_16 AC 27 ms
6,676 KB
testcase_17 AC 29 ms
6,676 KB
testcase_18 AC 29 ms
6,676 KB
testcase_19 AC 29 ms
6,676 KB
testcase_20 AC 2 ms
6,676 KB
testcase_21 AC 2 ms
6,676 KB
testcase_22 AC 29 ms
6,676 KB
testcase_23 AC 17 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

#define pb emplace_back
#define mp make_pair
 
using ll = long long;
using pii = pair<int,int>;
 
constexpr int mod = 998244353;
constexpr int inf = 0x3f3f3f3f;
constexpr int N = 2e5 + 10;

int n, a[N];
ll b[N];

void _main(){
  cin >> n;
  for(int i=1; i<=n; ++i) cin >> a[i];
  if(n == 1){
    b[1] = 1;
  } else if(n == 2){
    b[1] = b[2] = 3;
  } else {
    ll x = 1, y = 4, z = 5;
    for(int i=4; i<=n; ++i){
      x = x * 2 % mod;
      y = (y * 2 + x) % mod;
      z = (z * 2 + x) % mod;
    }
    for(int i=1; i<=n; ++i){
      b[i] = (y * i + z - 1ll * i * i % mod * x) % mod;
      if(b[i] < 0)  b[i] += mod;
    }
  }
  ll ans = 0;
  for(int i=1; i<=n; ++i) ans += a[i] * b[i] % mod;
  cout << ans % mod << '\n';
}

int main(){
  ios::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  _main();
  return 0;
}
0