結果
問題 | No.1330 Multiply or Divide |
ユーザー |
👑 ![]() |
提出日時 | 2021-01-08 23:57:48 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 695 bytes |
コンパイル時間 | 468 ms |
コンパイル使用メモリ | 81,996 KB |
実行使用メモリ | 157,228 KB |
最終ジャッジ日時 | 2024-11-16 18:57:29 |
合計ジャッジ時間 | 6,243 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 38 WA * 7 RE * 1 |
ソースコード
import sys input=sys.stdin.readline N,M,P=map(int,input().split()) A=set(map(int,input().split())) A=list(A) Max=max(A) T={} for b in A: a=b m=1 while b%P==0: b//=P m+=1 if b>1 and ((b not in T) or (T[b]>m)): T[b]=m if (not T) and Max<=M: print(-1) exit(0) def f(x,k): if k+1>=Y: return float("inf") if x in Memo: return Memo[x] elif x>M: return 0 elif x*Max>M: return 1 X=float("inf") for b in T: m=T[b] if k+m+1<Y: X=min(X,f(x*b,k+m)+m) Memo[x]=X return X Y=1 x=1 semi=max(T) while x*Max<=M: x*=semi Y+=1 Memo={} print(min(Y,f(1,0)))