結果

問題 No.2653 [Cherry 6th Tune] Re: start! (Make it Zero!)
ユーザー ゼットゼット
提出日時 2024-02-23 22:54:18
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 386 ms / 2,000 ms
コード長 887 bytes
コンパイル時間 342 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 114,560 KB
最終ジャッジ日時 2024-02-23 22:54:46
合計ジャッジ時間 14,201 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,460 KB
testcase_01 AC 171 ms
76,904 KB
testcase_02 AC 82 ms
76,264 KB
testcase_03 AC 102 ms
75,964 KB
testcase_04 AC 95 ms
90,876 KB
testcase_05 AC 92 ms
88,988 KB
testcase_06 AC 375 ms
80,372 KB
testcase_07 AC 386 ms
79,972 KB
testcase_08 AC 95 ms
112,388 KB
testcase_09 AC 92 ms
106,784 KB
testcase_10 AC 97 ms
111,404 KB
testcase_11 AC 98 ms
101,300 KB
testcase_12 AC 93 ms
106,944 KB
testcase_13 AC 127 ms
76,784 KB
testcase_14 AC 144 ms
76,644 KB
testcase_15 AC 130 ms
76,784 KB
testcase_16 AC 127 ms
76,788 KB
testcase_17 AC 128 ms
76,784 KB
testcase_18 AC 152 ms
76,784 KB
testcase_19 AC 133 ms
76,528 KB
testcase_20 AC 130 ms
76,784 KB
testcase_21 AC 128 ms
76,784 KB
testcase_22 AC 129 ms
76,784 KB
testcase_23 AC 98 ms
76,852 KB
testcase_24 AC 102 ms
76,480 KB
testcase_25 AC 97 ms
76,320 KB
testcase_26 AC 104 ms
77,492 KB
testcase_27 AC 119 ms
76,176 KB
testcase_28 AC 101 ms
77,592 KB
testcase_29 AC 99 ms
76,328 KB
testcase_30 AC 99 ms
76,216 KB
testcase_31 AC 96 ms
76,196 KB
testcase_32 AC 102 ms
76,392 KB
testcase_33 AC 112 ms
91,640 KB
testcase_34 AC 115 ms
98,544 KB
testcase_35 AC 122 ms
89,832 KB
testcase_36 AC 109 ms
87,380 KB
testcase_37 AC 147 ms
99,700 KB
testcase_38 AC 120 ms
94,804 KB
testcase_39 AC 107 ms
89,492 KB
testcase_40 AC 113 ms
93,672 KB
testcase_41 AC 105 ms
91,252 KB
testcase_42 AC 108 ms
94,580 KB
testcase_43 AC 322 ms
77,728 KB
testcase_44 AC 361 ms
77,920 KB
testcase_45 AC 373 ms
80,308 KB
testcase_46 AC 319 ms
77,720 KB
testcase_47 AC 350 ms
77,728 KB
testcase_48 AC 353 ms
78,280 KB
testcase_49 AC 384 ms
79,392 KB
testcase_50 AC 365 ms
78,156 KB
testcase_51 AC 325 ms
77,716 KB
testcase_52 AC 351 ms
78,268 KB
testcase_53 AC 99 ms
105,272 KB
testcase_54 AC 101 ms
107,640 KB
testcase_55 AC 129 ms
114,560 KB
testcase_56 AC 97 ms
105,068 KB
testcase_57 AC 104 ms
105,784 KB
testcase_58 AC 105 ms
106,920 KB
testcase_59 AC 114 ms
107,244 KB
testcase_60 AC 99 ms
106,144 KB
testcase_61 AC 100 ms
108,836 KB
testcase_62 AC 96 ms
106,360 KB
testcase_63 AC 121 ms
76,628 KB
testcase_64 AC 122 ms
76,756 KB
testcase_65 AC 121 ms
76,244 KB
testcase_66 AC 126 ms
76,896 KB
testcase_67 AC 126 ms
77,024 KB
testcase_68 AC 126 ms
76,784 KB
testcase_69 AC 136 ms
76,448 KB
testcase_70 AC 127 ms
76,772 KB
testcase_71 AC 136 ms
76,440 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

Q=int(input())
for _ in range(Q):
  N,M=map(int,input().split())
  A=list(map(int,input().split()))
  L=[]
  mod=M
  for i in range(N):
    if A[i]==-1:
      L.append(i)
  if len(L)==0:
    if (sum(A))%M!=0:
      print(0)
    else:
      result=N
      x=0
      for i in range(N):
        x+=A[i]
        x%=mod
        if x==0:
          result-=1
      print(result)
    continue
  mod=998244353
  count=len(L)
  p1=pow(M,count-1,mod)
  p2=pow(M,count-2,mod)
  result=p1*N
  result%=mod
  pos=L[0]
  x=0
  for i in range(pos):
    x+=A[i]
    x%=M
    if x==0:
      result-=p1
      result%=mod
  for i in range(len(L)-1):
    pos1=L[i]
    pos2=L[i+1]
    result-=(pos2-pos1)*p2
    result%=mod
  T={}
  T[0]=1
  x=0
  pos=L[-1]
  for i in range(pos+1,N):
    x+=A[i]
    x%=M
    if not x in T:
      T[x]=1
    else:
      T[x]+=1
  result-=T[x]*p1
  result%=mod
  print(result)
0