結果
| 問題 |
No.1330 Multiply or Divide
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-01-17 04:49:59 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 904 bytes |
| コンパイル時間 | 1,812 ms |
| コンパイル使用メモリ | 179,816 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-29 02:08:46 |
| 合計ジャッジ時間 | 5,381 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 45 WA * 1 |
ソースコード
#include<bits/stdc++.h>
// #include<atcoder/all>
using namespace std;
// using namespace atcoder;
using lint = long long;
#define endl '\n'
lint const mod = 1e9+7;
//long const mod = 998244353;
map<lint,lint>dp;
lint maxx;
lint n,m,p;
lint a[200000];
map<lint,lint>cost;
lint search(lint x){
if(x*maxx > m)return 1;
if(dp[x] != 0)return dp[x];
lint tmp = 1<<30;
for(auto pp: cost){
tmp = min(tmp, search(x*pp.second) + pp.first);
}
return dp[x] = tmp;
}
int main(){
cin >> n >> m >> p;
for(int i=0;i<n;i++)cin >> a[i];
sort(a,a+n);
maxx = a[n-1];
for(int i=0;i<n;i++){
int c = 1;
while(a[i] %p == 0){
a[i] /= p;
c++;
}
if(a[i] > 1)cost[c] = max(cost[c], a[i]);
}
if(cost.size() == 0){
cout << -1 << endl;
return 0;
}
cout << search(1) << endl;
}