結果

問題 No.2144 MM
ユーザー googol_S0googol_S0
提出日時 2022-12-02 22:06:43
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 696 bytes
コンパイル時間 459 ms
コンパイル使用メモリ 82,644 KB
実行使用メモリ 110,444 KB
最終ジャッジ日時 2024-04-18 06:06:49
合計ジャッジ時間 4,325 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
52,096 KB
testcase_01 AC 36 ms
51,968 KB
testcase_02 AC 37 ms
52,224 KB
testcase_03 AC 37 ms
52,352 KB
testcase_04 AC 39 ms
52,352 KB
testcase_05 AC 37 ms
52,224 KB
testcase_06 AC 37 ms
51,968 KB
testcase_07 AC 86 ms
103,040 KB
testcase_08 WA -
testcase_09 AC 81 ms
103,680 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 53 ms
72,320 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 37 ms
52,096 KB
testcase_26 AC 37 ms
52,224 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,(N+1)>>1]
S=0
P=N
for i in range(N):
  P-=1
  if (i^N)&1:
    S=(S-A[i])%M
  else:
    S=(S+A[i])%M
  C[(i^N)&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 -(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