結果

問題 No.1330 Multiply or Divide
ユーザー chocoruskchocorusk
提出日時 2021-01-09 17:02:03
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 133 ms / 2,000 ms
コード長 1,328 bytes
コンパイル時間 1,197 ms
コンパイル使用メモリ 127,244 KB
実行使用メモリ 5,180 KB
最終ジャッジ日時 2023-08-11 08:22:27
合計ジャッジ時間 4,867 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 66 ms
4,848 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 36 ms
4,920 KB
testcase_07 AC 133 ms
4,936 KB
testcase_08 AC 83 ms
5,180 KB
testcase_09 AC 87 ms
4,904 KB
testcase_10 AC 82 ms
4,980 KB
testcase_11 AC 81 ms
4,928 KB
testcase_12 AC 85 ms
4,908 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 77 ms
5,056 KB
testcase_19 AC 76 ms
4,904 KB
testcase_20 AC 76 ms
4,840 KB
testcase_21 AC 77 ms
5,140 KB
testcase_22 AC 77 ms
5,120 KB
testcase_23 AC 86 ms
4,980 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 2 ms
4,384 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 57 ms
4,512 KB
testcase_35 AC 18 ms
4,380 KB
testcase_36 AC 51 ms
4,396 KB
testcase_37 AC 46 ms
4,380 KB
testcase_38 AC 29 ms
4,380 KB
testcase_39 AC 21 ms
4,384 KB
testcase_40 AC 24 ms
4,380 KB
testcase_41 AC 14 ms
4,376 KB
testcase_42 AC 43 ms
4,384 KB
testcase_43 AC 49 ms
4,380 KB
testcase_44 AC 37 ms
4,904 KB
testcase_45 AC 37 ms
4,908 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <stack>
#include <array>
#include <list>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
    int n; cin>>n;
    ll m, p; cin>>m>>p;
    ll a[200020];
    for(int i=0; i<n; i++){
        cin>>a[i];
    }
    ll mx=*max_element(a, a+n);
    if(mx>m){
        cout<<1<<endl;
        return 0;
    }
    ll x[30];
    fill(x, x+30, 1);
    for(int i=0; i<n; i++){
        int c=0;
        ll b=a[i];
        while(b%p==0){
            b/=p;
            c++;
        }
        x[c]=max(x[c], b);
    }
    ll dp[1024]={};
    dp[0]=1;
    const ll MAX=1e9+7;
    for(int i=0; i<1024; i++){
        for(int j=0; i+j+1<1024 && j<30; j++){
            dp[i+j+1]=max(dp[i+j+1], min(dp[i]*x[j], MAX));
        }
    }
    for(int i=0; i<1024; i++){
        if(dp[i]>m/mx){
            cout<<i+1<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
    return 0;
}
0