結果
問題 |
No.1330 Multiply or Divide
|
ユーザー |
|
提出日時 | 2021-02-14 08:23:24 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 703 bytes |
コンパイル時間 | 262 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 108,672 KB |
最終ジャッジ日時 | 2024-07-21 13:50:51 |
合計ジャッジ時間 | 5,642 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 45 WA * 1 |
ソースコード
from heapq import heappop,heappush def main1(n,m,p,a): if any([x>m for x in a]):return 1 bd=m d={} for x in a: bd=min(bd,(m+1+x-1)//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>bd: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)