結果

問題 No.1330 Multiply or Divide
ユーザー 👑 deuteridayodeuteridayo
提出日時 2021-01-17 04:51:35
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 123 ms / 2,000 ms
コード長 986 bytes
コンパイル時間 1,675 ms
コンパイル使用メモリ 176,604 KB
実行使用メモリ 5,188 KB
最終ジャッジ日時 2023-08-19 10:34:39
合計ジャッジ時間 5,683 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 63 ms
5,188 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 36 ms
4,868 KB
testcase_07 AC 123 ms
4,880 KB
testcase_08 AC 90 ms
4,956 KB
testcase_09 AC 94 ms
4,896 KB
testcase_10 AC 92 ms
4,956 KB
testcase_11 AC 91 ms
5,180 KB
testcase_12 AC 91 ms
4,956 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 86 ms
4,864 KB
testcase_19 AC 88 ms
4,988 KB
testcase_20 AC 87 ms
4,852 KB
testcase_21 AC 88 ms
5,048 KB
testcase_22 AC 87 ms
4,896 KB
testcase_23 AC 83 ms
5,004 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 68 ms
4,564 KB
testcase_35 AC 18 ms
4,376 KB
testcase_36 AC 57 ms
4,380 KB
testcase_37 AC 51 ms
4,380 KB
testcase_38 AC 32 ms
4,380 KB
testcase_39 AC 22 ms
4,376 KB
testcase_40 AC 27 ms
4,376 KB
testcase_41 AC 14 ms
4,376 KB
testcase_42 AC 48 ms
4,376 KB
testcase_43 AC 54 ms
4,380 KB
testcase_44 AC 37 ms
4,956 KB
testcase_45 AC 37 ms
4,892 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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){
        if(m < maxx){
            cout << 1 << endl;
        }else{
            cout << -1 << endl;
        }
        return 0;
    }
    cout << search(1) << endl;
}
0