結果

問題 No.1330 Multiply or Divide
ユーザー persimmon-persimmonpersimmon-persimmon
提出日時 2021-02-14 08:31:41
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 233 ms / 2,000 ms
コード長 717 bytes
コンパイル時間 298 ms
コンパイル使用メモリ 86,704 KB
実行使用メモリ 106,816 KB
最終ジャッジ日時 2023-09-28 19:18:39
合計ジャッジ時間 7,661 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
71,216 KB
testcase_01 AC 142 ms
100,252 KB
testcase_02 AC 78 ms
71,232 KB
testcase_03 AC 81 ms
70,904 KB
testcase_04 AC 84 ms
71,276 KB
testcase_05 AC 80 ms
71,168 KB
testcase_06 AC 126 ms
106,236 KB
testcase_07 AC 233 ms
100,280 KB
testcase_08 AC 156 ms
104,376 KB
testcase_09 AC 160 ms
104,532 KB
testcase_10 AC 158 ms
104,424 KB
testcase_11 AC 157 ms
104,200 KB
testcase_12 AC 166 ms
104,264 KB
testcase_13 AC 82 ms
71,300 KB
testcase_14 AC 80 ms
71,372 KB
testcase_15 AC 80 ms
71,068 KB
testcase_16 AC 80 ms
71,276 KB
testcase_17 AC 79 ms
71,380 KB
testcase_18 AC 135 ms
103,880 KB
testcase_19 AC 137 ms
103,824 KB
testcase_20 AC 136 ms
104,108 KB
testcase_21 AC 135 ms
103,648 KB
testcase_22 AC 138 ms
103,832 KB
testcase_23 AC 145 ms
105,056 KB
testcase_24 AC 81 ms
71,228 KB
testcase_25 AC 80 ms
71,200 KB
testcase_26 AC 82 ms
71,216 KB
testcase_27 AC 81 ms
71,428 KB
testcase_28 AC 79 ms
71,276 KB
testcase_29 AC 81 ms
71,456 KB
testcase_30 AC 80 ms
71,228 KB
testcase_31 AC 81 ms
71,436 KB
testcase_32 AC 79 ms
71,428 KB
testcase_33 AC 82 ms
71,132 KB
testcase_34 AC 127 ms
96,076 KB
testcase_35 AC 94 ms
81,776 KB
testcase_36 AC 116 ms
98,780 KB
testcase_37 AC 114 ms
96,444 KB
testcase_38 AC 100 ms
87,908 KB
testcase_39 AC 96 ms
82,824 KB
testcase_40 AC 101 ms
85,060 KB
testcase_41 AC 93 ms
79,572 KB
testcase_42 AC 109 ms
94,048 KB
testcase_43 AC 115 ms
97,080 KB
testcase_44 AC 136 ms
106,512 KB
testcase_45 AC 138 ms
106,816 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappop,heappush
def main1(n,m,p,a):
  if any([x>m for x in a]):return 1
  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 len(d)==0:return -1
  todo=[[0,1]]
  costary=[0]*1000
  costary[0]=1
  while todo:
    c,v=heappop(todo)
    if costary[c]>v:continue
    if v>m:return c
    if v*mxv>m:return c+1
    for key,value in d.items():
      if costary[c+key]<v*value:
        costary[c+key]=v*value
        heappush(todo,[c+key,v*value])
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