結果

問題 No.2144 MM
ユーザー shobonvipshobonvip
提出日時 2022-12-02 23:30:09
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 882 bytes
コンパイル時間 186 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 106,752 KB
最終ジャッジ日時 2024-10-10 02:00:00
合計ジャッジ時間 6,885 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 13 WA * 22
権限があれば一括ダウンロードができます

ソースコード

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