結果

問題 No.1330 Multiply or Divide
ユーザー persimmon_t01persimmon_t01
提出日時 2021-01-08 22:16:14
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 219 ms / 2,000 ms
コード長 715 bytes
コンパイル時間 730 ms
コンパイル使用メモリ 87,236 KB
実行使用メモリ 109,276 KB
最終ジャッジ日時 2023-08-10 13:08:01
合計ジャッジ時間 7,094 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,012 KB
testcase_01 AC 122 ms
109,276 KB
testcase_02 AC 68 ms
71,364 KB
testcase_03 AC 72 ms
71,376 KB
testcase_04 AC 70 ms
70,996 KB
testcase_05 AC 71 ms
71,372 KB
testcase_06 AC 112 ms
105,716 KB
testcase_07 AC 219 ms
109,000 KB
testcase_08 AC 143 ms
101,876 KB
testcase_09 AC 150 ms
101,420 KB
testcase_10 AC 144 ms
101,628 KB
testcase_11 AC 139 ms
101,888 KB
testcase_12 AC 144 ms
101,368 KB
testcase_13 AC 71 ms
71,068 KB
testcase_14 AC 71 ms
71,420 KB
testcase_15 AC 72 ms
71,244 KB
testcase_16 AC 72 ms
71,216 KB
testcase_17 AC 72 ms
71,396 KB
testcase_18 AC 118 ms
100,392 KB
testcase_19 AC 121 ms
100,448 KB
testcase_20 AC 118 ms
100,480 KB
testcase_21 AC 118 ms
100,184 KB
testcase_22 AC 118 ms
100,264 KB
testcase_23 AC 133 ms
103,324 KB
testcase_24 AC 67 ms
71,240 KB
testcase_25 AC 65 ms
71,312 KB
testcase_26 AC 71 ms
71,428 KB
testcase_27 AC 67 ms
71,232 KB
testcase_28 AC 68 ms
71,416 KB
testcase_29 AC 68 ms
71,236 KB
testcase_30 AC 67 ms
71,048 KB
testcase_31 AC 68 ms
71,160 KB
testcase_32 AC 66 ms
71,284 KB
testcase_33 AC 73 ms
71,420 KB
testcase_34 AC 103 ms
100,648 KB
testcase_35 AC 80 ms
80,928 KB
testcase_36 AC 98 ms
97,628 KB
testcase_37 AC 95 ms
94,944 KB
testcase_38 AC 86 ms
87,120 KB
testcase_39 AC 81 ms
81,880 KB
testcase_40 AC 82 ms
84,152 KB
testcase_41 AC 76 ms
78,836 KB
testcase_42 AC 92 ms
92,724 KB
testcase_43 AC 98 ms
95,408 KB
testcase_44 AC 121 ms
106,192 KB
testcase_45 AC 119 ms
106,292 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def main(n,m,p,a):
  ma0=max(a)
  if ma0>m:return 1
  b=[1]*n
  for i in range(n):
    while a[i]%p==0:
      a[i]//=p
      b[i]+=1
  ma1=max(a)
  if ma1==1:
    print(-1)
    exit()
  ary=[0]*50
  for i in range(n):
    ary[b[i]]=max(ary[b[i]],a[i])
  ary=[[i,v] for i,v in enumerate(ary) if v!=0]
  from heapq import heappush,heappop
  todo=[[0,1]]
  inf=float('inf')
  seen=[0]*1000
  seen[0]=1
  # seen[i]:操作回数i回における最大
  while todo:
    i,v=heappop(todo)
    if v*ma0>m:return i+1
    for di,dv in ary:
      if i+di<1000 and seen[i+di]<v*dv:
        seen[i+di]=v*dv
        heappush(todo,[i+di,v*dv])
n,m,p=map(int,input().split())
a=list(map(int,input().split()))
print(main(n,m,p,a))

0