結果

問題 No.1330 Multiply or Divide
ユーザー persimmon-persimmonpersimmon-persimmon
提出日時 2021-02-14 08:28:19
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 227 ms / 2,000 ms
コード長 791 bytes
コンパイル時間 299 ms
コンパイル使用メモリ 87,044 KB
実行使用メモリ 104,404 KB
最終ジャッジ日時 2023-09-28 19:14:55
合計ジャッジ時間 7,710 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
71,192 KB
testcase_01 AC 142 ms
98,444 KB
testcase_02 AC 80 ms
71,344 KB
testcase_03 AC 85 ms
71,132 KB
testcase_04 AC 80 ms
71,080 KB
testcase_05 AC 78 ms
71,276 KB
testcase_06 AC 129 ms
104,228 KB
testcase_07 AC 227 ms
98,324 KB
testcase_08 AC 148 ms
102,548 KB
testcase_09 AC 156 ms
102,328 KB
testcase_10 AC 148 ms
102,776 KB
testcase_11 AC 153 ms
102,504 KB
testcase_12 AC 159 ms
102,712 KB
testcase_13 AC 82 ms
71,052 KB
testcase_14 AC 80 ms
71,256 KB
testcase_15 AC 80 ms
71,088 KB
testcase_16 AC 80 ms
71,376 KB
testcase_17 AC 83 ms
71,160 KB
testcase_18 AC 139 ms
102,464 KB
testcase_19 AC 140 ms
102,284 KB
testcase_20 AC 138 ms
102,128 KB
testcase_21 AC 138 ms
102,364 KB
testcase_22 AC 137 ms
102,548 KB
testcase_23 AC 138 ms
103,040 KB
testcase_24 AC 79 ms
71,248 KB
testcase_25 AC 79 ms
71,256 KB
testcase_26 AC 78 ms
71,316 KB
testcase_27 AC 81 ms
71,272 KB
testcase_28 AC 79 ms
71,364 KB
testcase_29 AC 77 ms
71,208 KB
testcase_30 AC 79 ms
71,152 KB
testcase_31 AC 79 ms
71,328 KB
testcase_32 AC 79 ms
71,328 KB
testcase_33 AC 80 ms
71,116 KB
testcase_34 AC 126 ms
95,956 KB
testcase_35 AC 94 ms
81,144 KB
testcase_36 AC 123 ms
97,612 KB
testcase_37 AC 111 ms
95,328 KB
testcase_38 AC 103 ms
87,084 KB
testcase_39 AC 96 ms
82,172 KB
testcase_40 AC 97 ms
84,324 KB
testcase_41 AC 95 ms
78,896 KB
testcase_42 AC 110 ms
93,400 KB
testcase_43 AC 116 ms
95,560 KB
testcase_44 AC 129 ms
104,236 KB
testcase_45 AC 127 ms
104,404 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappop,heappush
def main1(n,m,p,a):
  d={}
  mxv=0
  for x in a:
    mxv=max(mxv,x)
    cnt=1
    while x%p==0:
      cnt+=1
      x//=p
    if x==1:continue
    if cnt in d:d[cnt]=max(d[cnt],x)
    else:d[cnt]=x
  if mxv>m:return 1
  if len(d)==0:return -1
  todo=[[0,1]]
  costary=[0]*1000
  costary[0]=1
  ans=float('inf')
  while todo:
    c,v=heappop(todo)
    if costary[c]>v:continue
    if v>m:
      ans=min(ans,c)
      continue
    if v*mxv>m:
      ans=min(ans,c+1)
      continue
    for key,value in d.items():
      if costary[c+key]<v*value:
        costary[c+key]=v*value
        heappush(todo,[c+key,v*value])
  return ans

if __name__=='__main__':
  n,m,p=map(int,input().split())
  a=list(map(int,input().split()))
  ret1=main1(n,m,p,a)
  print(ret1)
0