結果
問題 |
No.1330 Multiply or Divide
|
ユーザー |
|
提出日時 | 2021-02-14 08:31:41 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 176 ms / 2,000 ms |
コード長 | 717 bytes |
コンパイル時間 | 685 ms |
コンパイル使用メモリ | 81,844 KB |
実行使用メモリ | 108,656 KB |
最終ジャッジ日時 | 2025-06-20 01:28:51 |
合計ジャッジ時間 | 5,590 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 51 |
ソースコード
from heapq import heappop,heappush def main1(n,m,p,a): if any([x>m for x in a]):return 1 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 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>m:return c if v*mxv>m: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)