結果

問題 No.2144 MM
ユーザー shobonvipshobonvip
提出日時 2022-12-02 23:31:17
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 383 ms / 2,000 ms
コード長 926 bytes
コンパイル時間 347 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 106,852 KB
最終ジャッジ日時 2024-04-18 08:45:22
合計ジャッジ時間 6,865 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,564 KB
testcase_01 AC 37 ms
53,488 KB
testcase_02 AC 36 ms
52,888 KB
testcase_03 AC 36 ms
53,684 KB
testcase_04 AC 36 ms
52,808 KB
testcase_05 AC 36 ms
52,800 KB
testcase_06 AC 36 ms
52,472 KB
testcase_07 AC 81 ms
103,528 KB
testcase_08 AC 382 ms
106,852 KB
testcase_09 AC 79 ms
103,260 KB
testcase_10 AC 380 ms
106,676 KB
testcase_11 AC 378 ms
106,664 KB
testcase_12 AC 372 ms
106,624 KB
testcase_13 AC 379 ms
106,196 KB
testcase_14 AC 383 ms
106,528 KB
testcase_15 AC 328 ms
102,612 KB
testcase_16 AC 138 ms
81,712 KB
testcase_17 AC 308 ms
99,132 KB
testcase_18 AC 51 ms
73,372 KB
testcase_19 AC 314 ms
99,316 KB
testcase_20 AC 275 ms
96,604 KB
testcase_21 AC 214 ms
90,032 KB
testcase_22 AC 95 ms
75,232 KB
testcase_23 AC 284 ms
97,200 KB
testcase_24 AC 126 ms
79,972 KB
testcase_25 AC 34 ms
52,928 KB
testcase_26 AC 36 ms
52,624 KB
testcase_27 AC 36 ms
52,704 KB
testcase_28 AC 39 ms
52,896 KB
testcase_29 AC 37 ms
52,952 KB
testcase_30 AC 38 ms
53,352 KB
testcase_31 AC 35 ms
52,560 KB
testcase_32 AC 38 ms
53,696 KB
testcase_33 AC 35 ms
52,264 KB
testcase_34 AC 36 ms
52,804 KB
testcase_35 AC 35 ms
52,192 KB
testcase_36 AC 36 ms
52,744 KB
testcase_37 AC 37 ms
54,128 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 998244353

def isgood(n,m,a):
	g = 0
	for i in range(n):
		if i % 2 == 0:
			g += a[i]
		else:
			g -= a[i]
	if g % m == 0:
		return True
	return False

def count(n,m,e,l,t):
	if n % 2 == 0:
		r = (pow(m-1, n, mod) - 1) * pow(m, mod-2, mod) % mod
		if t == 0:
			if e <= 0 < e+l or e <= m < e+l: return (l*r+1) % mod
		else:
			if e-l < 0 <= e or e-l < m <= e: return (l*r+1) % mod
		return l*r % mod
	else:
		r = (pow(m-1, n, mod) + 1) * pow(m, mod-2, mod) % mod
		if t == 1:
			if e-l < 1 <= e or e-l < 1-m <= e: return (l*r-1) % mod
			return l*r % mod
		else:
			if e <= m-1 < e+l or e <= 2*m-1 < e+l: return (l*r-1) % mod
			return l*r % mod

n,m = map(int,input().split())
a = list(map(int,input().split()))

if isgood(n,m,a):
	g = 0
	ans = 0
	for i in range(n):
		ans += count(n-i-1,m,g,a[i],i%2)
		if i%2 == 0:
			g = (g+a[i]) % m
		else:
			g = (g-a[i]) % m
		#print(ans)
	print((ans+1) % mod)
else:
	print(-1)
0