結果
| 問題 |
No.1330 Multiply or Divide
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-02-14 08:28:19 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 185 ms / 2,000 ms |
| コード長 | 791 bytes |
| コンパイル時間 | 219 ms |
| コンパイル使用メモリ | 82,172 KB |
| 実行使用メモリ | 106,944 KB |
| 最終ジャッジ日時 | 2025-06-20 01:28:46 |
| 合計ジャッジ時間 | 5,527 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 51 |
ソースコード
from heapq import heappop,heappush
def main1(n,m,p,a):
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 mxv>m:return 1
if len(d)==0:return -1
todo=[[0,1]]
costary=[0]*1000
costary[0]=1
ans=float('inf')
while todo:
c,v=heappop(todo)
if costary[c]>v:continue
if v>m:
ans=min(ans,c)
continue
if v*mxv>m:
ans=min(ans,c+1)
continue
for key,value in d.items():
if costary[c+key]<v*value:
costary[c+key]=v*value
heappush(todo,[c+key,v*value])
return ans
if __name__=='__main__':
n,m,p=map(int,input().split())
a=list(map(int,input().split()))
ret1=main1(n,m,p,a)
print(ret1)