結果

問題 No.1330 Multiply or Divide
ユーザー persimmon_t01persimmon_t01
提出日時 2021-01-08 22:13:43
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 715 bytes
コンパイル時間 787 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 107,648 KB
最終ジャッジ日時 2024-04-28 03:27:49
合計ジャッジ時間 5,325 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
52,864 KB
testcase_01 AC 95 ms
106,624 KB
testcase_02 AC 40 ms
52,096 KB
testcase_03 AC 41 ms
52,480 KB
testcase_04 AC 41 ms
52,736 KB
testcase_05 AC 40 ms
52,952 KB
testcase_06 AC 87 ms
99,072 KB
testcase_07 AC 194 ms
107,648 KB
testcase_08 AC 121 ms
101,888 KB
testcase_09 AC 130 ms
101,740 KB
testcase_10 AC 125 ms
102,260 KB
testcase_11 AC 120 ms
101,700 KB
testcase_12 AC 123 ms
101,688 KB
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 AC 41 ms
53,248 KB
testcase_17 AC 42 ms
52,352 KB
testcase_18 AC 102 ms
102,016 KB
testcase_19 AC 101 ms
101,736 KB
testcase_20 AC 98 ms
101,888 KB
testcase_21 AC 100 ms
102,144 KB
testcase_22 AC 100 ms
101,592 KB
testcase_23 AC 111 ms
100,364 KB
testcase_24 AC 40 ms
52,240 KB
testcase_25 AC 39 ms
52,224 KB
testcase_26 AC 40 ms
52,756 KB
testcase_27 AC 38 ms
51,840 KB
testcase_28 AC 39 ms
52,736 KB
testcase_29 AC 41 ms
52,224 KB
testcase_30 AC 40 ms
52,096 KB
testcase_31 AC 41 ms
52,328 KB
testcase_32 AC 43 ms
51,968 KB
testcase_33 AC 45 ms
52,276 KB
testcase_34 AC 86 ms
95,872 KB
testcase_35 AC 58 ms
68,852 KB
testcase_36 AC 81 ms
91,464 KB
testcase_37 AC 79 ms
88,320 KB
testcase_38 AC 68 ms
77,312 KB
testcase_39 AC 60 ms
70,144 KB
testcase_40 AC 62 ms
73,216 KB
testcase_41 AC 53 ms
66,048 KB
testcase_42 AC 72 ms
85,632 KB
testcase_43 AC 77 ms
88,960 KB
testcase_44 AC 101 ms
99,840 KB
testcase_45 AC 100 ms
100,480 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]*30
  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