結果

問題 No.1330 Multiply or Divide
ユーザー deuteridayo
提出日時 2021-01-17 04:34:46
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,053 bytes
コンパイル時間 1,836 ms
コンパイル使用メモリ 179,424 KB
実行使用メモリ 15,872 KB
最終ジャッジ日時 2024-11-29 02:08:25
合計ジャッジ時間 7,103 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 32 WA * 14
権限があれば一括ダウンロードができます

ソースコード

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];
    vector<vector<lint>>pa(200000);
lint search(lint x){
    if(x >= maxx)return 1;
    if(dp[x] != 0)return dp[x];

    lint tmp = 0;
    for(int i=0;i<n;i++){
        if(pa[i][0] > 1){
            tmp = max(tmp, search(x * pa[i][0]) + pa[i][1]);
        }
    }
    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 = ((m+1)/a[n-1]);
    while(maxx * a[n-1] <= m)maxx++;
    for(int i=0;i<n;i++){
        pa[i] = {a[i], 1};
        while(pa[i][0] % p == 0){
            pa[i][0] /= p;
            pa[i][1]++;
        }
    }
    bool chk = false;
    for(int i=0;i<n;i++){
        if(pa[i][0] > 1)chk = true;
    }
    if(!chk){
        cout << -1 << endl;
        return 0;
    }
    cout << search(1) << endl;
}
0