結果
問題 | No.2111 Sum of Diff |
ユーザー |
![]() |
提出日時 | 2022-10-28 22:56:48 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 87 ms / 2,000 ms |
コード長 | 687 bytes |
コンパイル時間 | 1,491 ms |
コンパイル使用メモリ | 168,396 KB |
実行使用メモリ | 9,600 KB |
最終ジャッジ日時 | 2024-07-06 02:10:17 |
合計ジャッジ時間 | 3,671 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 20 |
ソースコード
#include <bits/stdc++.h> using namespace std; int main() { int64_t n; cin >> n; vector<int64_t> a(n); for(int64_t i = 0; i < n; i++) cin >> a[i]; const int64_t mod = 998244353; vector<int64_t> b(n - 1); for(int64_t i = 0; i < n - 1; i++) b[i] = (a[i] - a[i + 1] + mod) % mod; vector<int64_t> pow2(n + 1); pow2[1] = 2; for(int64_t i = 2; i <= n; i++) { pow2[i] = pow2[i - 1] * 2; pow2[i] %= mod; } vector<int64_t> c(n - 1); for(int64_t i = 1; i <= n - 1; i++) { c[i - 1] = (pow2[i] - 1) * (pow2[n - i] - 1); c[i - 1] %= mod; } int64_t ans = 0; for(int64_t i = 0; i < n - 1; i++) { ans += b[i] * c[i]; ans %= mod; } cout << ans << endl; return 0; }