結果

問題 No.2144 MM
ユーザー shobonvipshobonvip
提出日時 2022-12-02 23:19:49
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 787 bytes
コンパイル時間 395 ms
コンパイル使用メモリ 82,312 KB
実行使用メモリ 106,784 KB
最終ジャッジ日時 2024-04-18 08:35:16
合計ジャッジ時間 7,325 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 40 ms
52,520 KB
testcase_02 AC 37 ms
52,732 KB
testcase_03 AC 46 ms
53,356 KB
testcase_04 AC 37 ms
52,460 KB
testcase_05 AC 37 ms
52,396 KB
testcase_06 WA -
testcase_07 AC 81 ms
104,048 KB
testcase_08 WA -
testcase_09 AC 80 ms
103,360 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 51 ms
72,436 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 36 ms
51,936 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 AC 35 ms
52,568 KB
testcase_34 AC 37 ms
53,560 KB
testcase_35 WA -
testcase_36 AC 36 ms
53,036 KB
testcase_37 AC 36 ms
52,756 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 e-l < 0 <= 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-l < m-1 <= e or e-l < -1 <= e: 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