結果

問題 No.1330 Multiply or Divide
ユーザー persimmon_t01persimmon_t01
提出日時 2021-01-08 22:16:14
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 203 ms / 2,000 ms
コード長 715 bytes
コンパイル時間 265 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 107,648 KB
最終ジャッジ日時 2024-04-28 06:21:19
合計ジャッジ時間 5,222 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
52,736 KB
testcase_01 AC 109 ms
106,112 KB
testcase_02 AC 42 ms
51,840 KB
testcase_03 AC 43 ms
52,352 KB
testcase_04 AC 42 ms
52,352 KB
testcase_05 AC 44 ms
52,352 KB
testcase_06 AC 96 ms
98,432 KB
testcase_07 AC 203 ms
107,648 KB
testcase_08 AC 130 ms
102,016 KB
testcase_09 AC 135 ms
102,016 KB
testcase_10 AC 132 ms
101,888 KB
testcase_11 AC 126 ms
102,144 KB
testcase_12 AC 130 ms
101,632 KB
testcase_13 AC 44 ms
52,864 KB
testcase_14 AC 45 ms
52,480 KB
testcase_15 AC 43 ms
52,608 KB
testcase_16 AC 43 ms
52,480 KB
testcase_17 AC 45 ms
52,608 KB
testcase_18 AC 109 ms
102,144 KB
testcase_19 AC 108 ms
101,760 KB
testcase_20 AC 107 ms
102,144 KB
testcase_21 AC 106 ms
101,888 KB
testcase_22 AC 108 ms
101,760 KB
testcase_23 AC 120 ms
100,444 KB
testcase_24 AC 43 ms
51,840 KB
testcase_25 AC 42 ms
52,096 KB
testcase_26 AC 44 ms
52,096 KB
testcase_27 AC 42 ms
51,968 KB
testcase_28 AC 42 ms
51,968 KB
testcase_29 AC 41 ms
51,968 KB
testcase_30 AC 42 ms
51,840 KB
testcase_31 AC 42 ms
52,096 KB
testcase_32 AC 42 ms
51,712 KB
testcase_33 AC 44 ms
52,480 KB
testcase_34 AC 85 ms
95,872 KB
testcase_35 AC 56 ms
68,352 KB
testcase_36 AC 81 ms
91,520 KB
testcase_37 AC 77 ms
87,680 KB
testcase_38 AC 66 ms
76,544 KB
testcase_39 AC 62 ms
69,888 KB
testcase_40 AC 62 ms
72,832 KB
testcase_41 AC 55 ms
65,280 KB
testcase_42 AC 74 ms
84,864 KB
testcase_43 AC 78 ms
88,832 KB
testcase_44 AC 102 ms
100,096 KB
testcase_45 AC 100 ms
100,096 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