結果

問題 No.2144 MM
ユーザー rtyurtyu
提出日時 2023-01-28 22:57:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 27 ms / 2,000 ms
コード長 800 bytes
コンパイル時間 656 ms
コンパイル使用メモリ 67,408 KB
実行使用メモリ 7,504 KB
最終ジャッジ日時 2023-09-11 09:35:40
合計ジャッジ時間 2,706 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 26 ms
7,228 KB
testcase_08 AC 26 ms
7,336 KB
testcase_09 AC 26 ms
7,372 KB
testcase_10 AC 27 ms
7,228 KB
testcase_11 AC 26 ms
7,504 KB
testcase_12 AC 26 ms
7,240 KB
testcase_13 AC 25 ms
7,224 KB
testcase_14 AC 27 ms
7,352 KB
testcase_15 AC 23 ms
6,668 KB
testcase_16 AC 7 ms
4,380 KB
testcase_17 AC 19 ms
6,468 KB
testcase_18 AC 9 ms
4,616 KB
testcase_19 AC 21 ms
6,484 KB
testcase_20 AC 18 ms
5,972 KB
testcase_21 AC 14 ms
5,332 KB
testcase_22 AC 5 ms
4,376 KB
testcase_23 AC 19 ms
6,080 KB
testcase_24 AC 7 ms
4,380 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 1 ms
4,376 KB
testcase_35 AC 2 ms
4,376 KB
testcase_36 AC 1 ms
4,376 KB
testcase_37 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
using namespace std;

const long long md = 998244353;

int c[200009];
long long d[200009][2];

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m; cin >> n >> m;
	d[n][0] = 1;
	for (int i = n - 1; i >= 1; i--) {
		c[i] = ((n - i) & 1);
		d[i][0] = ((d[i + 1][1]) * (m - 1)) % md;
		d[i][1] = (d[i + 1][1] * (m - 2) + d[i + 1][0]) % md;
	}
	int s = 0;
	long long ans = 1;
	for (int i = 1; i <= n; i++) {
		int a; cin >> a;
		if ((n - i) & 1) s = (s - a + m) % m;
		else s = (s + a) % m;
		int ds = (s - c[i] + m) % m;
		if ((n - i) & 1) ds = (c[i] - s + m) % m;
		if (0 < ds && ds <= a) ans = (ans + d[i][0] + d[i][1] * (a - 1)) % md;
		else ans = (ans + d[i][1] * a) % md;
	}
	if (s) cout << -1 << '\n';
	else cout << ans << '\n';
	return 0;
}
0