結果

問題 No.2144 MM
ユーザー googol_S0googol_S0
提出日時 2022-12-02 22:12:06
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 111 ms / 2,000 ms
コード長 695 bytes
コンパイル時間 3,243 ms
コンパイル使用メモリ 82,124 KB
実行使用メモリ 110,200 KB
最終ジャッジ日時 2024-04-18 06:30:34
合計ジャッジ時間 5,163 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
51,968 KB
testcase_01 AC 34 ms
51,968 KB
testcase_02 AC 35 ms
51,968 KB
testcase_03 AC 34 ms
52,096 KB
testcase_04 AC 35 ms
51,968 KB
testcase_05 AC 34 ms
52,224 KB
testcase_06 AC 33 ms
52,096 KB
testcase_07 AC 77 ms
102,912 KB
testcase_08 AC 111 ms
110,200 KB
testcase_09 AC 76 ms
103,424 KB
testcase_10 AC 110 ms
109,968 KB
testcase_11 AC 108 ms
110,072 KB
testcase_12 AC 107 ms
109,624 KB
testcase_13 AC 107 ms
109,876 KB
testcase_14 AC 111 ms
109,816 KB
testcase_15 AC 104 ms
107,916 KB
testcase_16 AC 65 ms
80,392 KB
testcase_17 AC 108 ms
105,080 KB
testcase_18 AC 50 ms
72,448 KB
testcase_19 AC 109 ms
104,960 KB
testcase_20 AC 99 ms
103,144 KB
testcase_21 AC 93 ms
98,012 KB
testcase_22 AC 58 ms
72,704 KB
testcase_23 AC 101 ms
103,040 KB
testcase_24 AC 65 ms
77,696 KB
testcase_25 AC 34 ms
52,352 KB
testcase_26 AC 34 ms
52,224 KB
testcase_27 AC 34 ms
52,352 KB
testcase_28 AC 37 ms
52,992 KB
testcase_29 AC 35 ms
52,736 KB
testcase_30 AC 37 ms
52,992 KB
testcase_31 AC 36 ms
52,096 KB
testcase_32 AC 38 ms
53,760 KB
testcase_33 AC 35 ms
52,076 KB
testcase_34 AC 35 ms
52,352 KB
testcase_35 AC 34 ms
52,096 KB
testcase_36 AC 35 ms
52,480 KB
testcase_37 AC 34 ms
52,224 KB
権限があれば一括ダウンロードができます

ソースコード

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