結果

問題 No.1330 Multiply or Divide
ユーザー kappybarkappybar
提出日時 2021-01-08 22:32:27
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,429 bytes
コンパイル時間 1,614 ms
コンパイル使用メモリ 167,396 KB
実行使用メモリ 8,044 KB
最終ジャッジ日時 2023-08-10 12:31:58
合計ジャッジ時間 5,414 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 69 ms
8,044 KB
testcase_02 WA -
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 37 ms
7,776 KB
testcase_07 AC 142 ms
7,892 KB
testcase_08 AC 86 ms
7,768 KB
testcase_09 AC 88 ms
7,724 KB
testcase_10 AC 86 ms
7,812 KB
testcase_11 AC 84 ms
7,900 KB
testcase_12 AC 85 ms
7,884 KB
testcase_13 AC 2 ms
4,376 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 81 ms
7,784 KB
testcase_19 AC 81 ms
7,780 KB
testcase_20 AC 81 ms
7,900 KB
testcase_21 AC 82 ms
7,776 KB
testcase_22 AC 83 ms
7,996 KB
testcase_23 AC 88 ms
7,764 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 2 ms
4,384 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 61 ms
6,524 KB
testcase_35 AC 18 ms
4,380 KB
testcase_36 AC 54 ms
6,148 KB
testcase_37 AC 50 ms
5,660 KB
testcase_38 AC 31 ms
4,996 KB
testcase_39 AC 22 ms
4,380 KB
testcase_40 AC 26 ms
4,460 KB
testcase_41 AC 15 ms
4,380 KB
testcase_42 AC 46 ms
5,612 KB
testcase_43 AC 52 ms
5,940 KB
testcase_44 AC 46 ms
7,732 KB
testcase_45 AC 49 ms
7,732 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define chmin(x,y) x = min((x),(y));
#define chmax(x,y) x = max((x),(y));
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
const int INF = 1e9;
const long long LINF = 1e17;
const int MOD = 1000000007;
//const int MOD = 998244353;
const double PI = 3.14159265358979323846;

int main(){
    ll n,m,p;
    cin >> n >> m >> p;
    vector<ll> a(n);
    vector<ll> b(n);
    vector<ll> cnt(n,1);
    ll mx = 0;
    int mx_idx = -1;
    bool ok = false;
    rep(i,n){
        cin >> a[i];
        if(mx < a[i]){
            mx = a[i];
            mx_idx = i;
        }
        b[i] = a[i];
        while(b[i]%p==0){
            b[i] /= p;
            ++cnt[i];
        }
        if(b[i]!=1) ok = true;
    }
    if(!ok && mx <= m){
        cout << -1 << endl;
        return 0;
    }
    ll ans = INF;
    rep(i,n){
        if(b[i]==1) continue;
        ll x = 1;
        ll res = 0;
        while(x <= m){
            if(x*a[i] > m){
                x *= a[i];
                res ++;
            }else{
                x *= b[i];
                res += cnt[i];
            }
        }
        ans = min(ans,res);
        res = 1;
        x = mx;
        while(x <= m){
            x *= b[i];
            res += cnt[i];
        }
        ans = min(ans,res);
    }
    cout << ans << endl;

    return 0;
}
0