結果

問題 No.1330 Multiply or Divide
ユーザー persimmon-persimmonpersimmon-persimmon
提出日時 2021-02-14 08:23:24
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 703 bytes
コンパイル時間 551 ms
コンパイル使用メモリ 87,048 KB
実行使用メモリ 106,980 KB
最終ジャッジ日時 2023-09-28 19:09:08
合計ジャッジ時間 7,864 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 151 ms
100,472 KB
testcase_02 AC 80 ms
71,480 KB
testcase_03 AC 78 ms
71,052 KB
testcase_04 AC 78 ms
71,408 KB
testcase_05 AC 77 ms
71,356 KB
testcase_06 AC 126 ms
106,316 KB
testcase_07 AC 230 ms
100,400 KB
testcase_08 AC 153 ms
104,480 KB
testcase_09 AC 158 ms
104,464 KB
testcase_10 AC 151 ms
104,348 KB
testcase_11 AC 153 ms
104,804 KB
testcase_12 AC 159 ms
104,388 KB
testcase_13 AC 78 ms
71,204 KB
testcase_14 AC 79 ms
71,188 KB
testcase_15 AC 78 ms
71,552 KB
testcase_16 AC 77 ms
71,412 KB
testcase_17 AC 78 ms
71,512 KB
testcase_18 AC 131 ms
103,964 KB
testcase_19 AC 131 ms
103,956 KB
testcase_20 AC 131 ms
103,900 KB
testcase_21 AC 131 ms
103,724 KB
testcase_22 AC 132 ms
104,016 KB
testcase_23 AC 141 ms
104,968 KB
testcase_24 AC 76 ms
71,316 KB
testcase_25 AC 76 ms
71,488 KB
testcase_26 AC 78 ms
71,232 KB
testcase_27 AC 78 ms
71,348 KB
testcase_28 AC 77 ms
71,316 KB
testcase_29 AC 77 ms
71,460 KB
testcase_30 AC 76 ms
71,508 KB
testcase_31 AC 78 ms
71,056 KB
testcase_32 AC 77 ms
71,576 KB
testcase_33 AC 78 ms
71,472 KB
testcase_34 AC 121 ms
96,152 KB
testcase_35 AC 90 ms
81,616 KB
testcase_36 AC 114 ms
99,300 KB
testcase_37 AC 111 ms
96,288 KB
testcase_38 AC 100 ms
87,928 KB
testcase_39 AC 92 ms
82,740 KB
testcase_40 AC 96 ms
84,868 KB
testcase_41 AC 87 ms
79,680 KB
testcase_42 AC 106 ms
94,260 KB
testcase_43 AC 112 ms
97,048 KB
testcase_44 AC 135 ms
106,848 KB
testcase_45 AC 135 ms
106,980 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappop,heappush
def main1(n,m,p,a):
  if any([x>m for x in a]):return 1
  bd=m
  d={}
  for x in a:
    bd=min(bd,(m+1+x-1)//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>bd: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