結果

問題 No.2144 MM
ユーザー とりゐとりゐ
提出日時 2022-12-02 22:23:32
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 752 bytes
コンパイル時間 136 ms
コンパイル使用メモリ 82,300 KB
実行使用メモリ 107,076 KB
最終ジャッジ日時 2024-04-18 06:42:56
合計ジャッジ時間 4,086 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
52,224 KB
testcase_01 AC 35 ms
51,840 KB
testcase_02 AC 67 ms
59,392 KB
testcase_03 AC 34 ms
51,968 KB
testcase_04 AC 33 ms
51,840 KB
testcase_05 WA -
testcase_06 AC 65 ms
59,264 KB
testcase_07 AC 77 ms
102,912 KB
testcase_08 RE -
testcase_09 AC 79 ms
103,424 KB
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 AC 51 ms
72,832 KB
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 AC 116 ms
59,392 KB
testcase_26 AC 36 ms
52,096 KB
testcase_27 AC 90 ms
59,520 KB
testcase_28 WA -
testcase_29 RE -
testcase_30 RE -
testcase_31 WA -
testcase_32 RE -
testcase_33 AC 40 ms
59,392 KB
testcase_34 AC 43 ms
59,520 KB
testcase_35 WA -
testcase_36 WA -
testcase_37 AC 33 ms
52,224 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# O(N*M)

n,m=map(int,input().split())
a=list(map(int,input().split()))
odd=0
even=0
for i in range(n):
  if i%2==0:
    odd+=a[i]
  else:
    even+=a[i]
if (odd-even)%m!=0:
  print(-1)
  exit()
if n*m>=5*10**7:
  raise Exception

mod=998244353
M=m-1
powM=[1]

for i in range(n+10):
  powM.append(powM[-1]*M%mod)

ans=0
res=0
for i in range(n):
  ai=a[i]
  k=n-1-i
  x=powM[k]
  if k%2==0:
    y=(x-1)*pow(m,mod-2,mod)
    y%=mod
  else:
    y=(x+1)*pow(m,mod-2,mod)
    y%=mod
  for j in range(ai):
    if k%2==0:
      if (res+j)%m==0:
        ans+=y+1
      else:
        ans+=y
    else:
      if (res-j+1)%m==0:
        ans+=y-1
      else:
        ans+=y
  if i%2==0:
    res+=ai
  else:
    res-=ai
  ans%=mod
  #print(x,y)
ans+=1
print(ans%mod)
0