結果

問題 No.2144 MM
ユーザー shobonvipshobonvip
提出日時 2022-12-02 23:30:09
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 882 bytes
コンパイル時間 224 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 107,136 KB
最終ジャッジ日時 2024-04-18 08:44:46
合計ジャッジ時間 7,078 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
52,224 KB
testcase_01 AC 36 ms
52,224 KB
testcase_02 AC 36 ms
52,608 KB
testcase_03 AC 37 ms
51,840 KB
testcase_04 AC 41 ms
52,224 KB
testcase_05 AC 36 ms
51,968 KB
testcase_06 AC 36 ms
52,224 KB
testcase_07 AC 83 ms
102,912 KB
testcase_08 WA -
testcase_09 AC 79 ms
102,912 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 54 ms
72,576 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 37 ms
52,592 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 38 ms
52,736 KB
testcase_32 WA -
testcase_33 AC 38 ms
52,224 KB
testcase_34 AC 37 ms
52,224 KB
testcase_35 WA -
testcase_36 AC 39 ms
51,840 KB
testcase_37 AC 38 ms
52,352 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)
		g = (g+a[i]) % m
		#print(ans)
	print((ans+1) % mod)
else:
	print(-1)
0