結果

問題 No.2111 Sum of Diff
ユーザー Kome_soudouKome_soudou
提出日時 2022-10-28 22:56:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 81 ms / 2,000 ms
コード長 687 bytes
コンパイル時間 2,355 ms
コンパイル使用メモリ 167,440 KB
実行使用メモリ 9,436 KB
最終ジャッジ日時 2023-09-20 06:08:32
合計ジャッジ時間 3,974 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 80 ms
9,324 KB
testcase_03 AC 55 ms
7,300 KB
testcase_04 AC 13 ms
4,384 KB
testcase_05 AC 80 ms
9,380 KB
testcase_06 AC 80 ms
9,372 KB
testcase_07 AC 21 ms
4,680 KB
testcase_08 AC 28 ms
5,084 KB
testcase_09 AC 6 ms
4,376 KB
testcase_10 AC 9 ms
4,380 KB
testcase_11 AC 39 ms
5,848 KB
testcase_12 AC 38 ms
5,892 KB
testcase_13 AC 25 ms
4,872 KB
testcase_14 AC 65 ms
8,132 KB
testcase_15 AC 77 ms
9,012 KB
testcase_16 AC 34 ms
5,616 KB
testcase_17 AC 81 ms
9,324 KB
testcase_18 AC 26 ms
5,028 KB
testcase_19 AC 60 ms
7,796 KB
testcase_20 AC 80 ms
9,436 KB
testcase_21 AC 3 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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