結果

問題 No.2144 MM
ユーザー googol_S0googol_S0
提出日時 2022-12-02 21:54:36
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 719 bytes
コンパイル時間 249 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 110,288 KB
最終ジャッジ日時 2024-04-18 05:48:41
合計ジャッジ時間 4,103 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
52,352 KB
testcase_01 AC 35 ms
51,968 KB
testcase_02 AC 35 ms
52,096 KB
testcase_03 AC 36 ms
52,352 KB
testcase_04 AC 40 ms
52,352 KB
testcase_05 AC 36 ms
52,608 KB
testcase_06 WA -
testcase_07 AC 80 ms
103,296 KB
testcase_08 WA -
testcase_09 AC 79 ms
103,228 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 52 ms
72,736 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 36 ms
52,724 KB
testcase_26 AC 36 ms
52,096 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 37 ms
52,352 KB
testcase_36 WA -
testcase_37 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

mod=998244353
N,M=map(int,input().split())
A=list(map(int,input().split()))
S=0
for i in range(N):
  if i&1:
    S-=A[i]
  else:
    S+=A[i]
if S%M:
  print(-1)
  exit()
DP=[[0,0] for i in range(N+1)]
DP[0][1]=1
for i in range(N):
  DP[i+1][1]=(DP[i][0]*(M-1))%mod
  DP[i+1][0]=(DP[i][0]*(M-2)+DP[i][1])%mod
ANS=1
C=[(N+1)>>1,N>>1]
S=0
P=N
for i in range(N):
  P-=1
  if i&1:
    S=(S+A[i])%M
  else:
    S=(S-A[i])%M
  C[i&1]-=1
  if C[0]==C[1]:
    if -S%M<A[i]:
      ANS=(ANS+DP[P][1]+DP[P][0]*(A[i]-1))%mod
    else:
      ANS=(ANS+DP[P][0]*A[i])%mod
  else:
    if C[0]<C[1]:
      S=-S%M
    if -(S+1)%M<A[i]:
      ANS=(ANS+DP[P][1]+DP[P][0]*(A[i]-1))%mod
    else:
      ANS=(ANS+DP[P][0]*A[i])%mod
print(ANS)
0