結果

問題 No.1330 Multiply or Divide
ユーザー yuji9511yuji9511
提出日時 2021-01-09 13:45:48
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,662 bytes
コンパイル時間 2,277 ms
コンパイル使用メモリ 201,664 KB
実行使用メモリ 7,928 KB
最終ジャッジ日時 2023-08-11 04:10:03
合計ジャッジ時間 5,809 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 27 ms
7,812 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 23 ms
7,840 KB
testcase_07 AC 97 ms
7,924 KB
testcase_08 AC 35 ms
7,760 KB
testcase_09 AC 39 ms
7,804 KB
testcase_10 AC 36 ms
7,812 KB
testcase_11 AC 34 ms
7,860 KB
testcase_12 AC 35 ms
7,832 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 29 ms
7,928 KB
testcase_19 AC 30 ms
7,816 KB
testcase_20 AC 30 ms
7,840 KB
testcase_21 AC 30 ms
7,704 KB
testcase_22 AC 30 ms
7,712 KB
testcase_23 AC 33 ms
7,760 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 23 ms
6,524 KB
testcase_35 AC 7 ms
4,376 KB
testcase_36 AC 21 ms
6,224 KB
testcase_37 AC 18 ms
5,652 KB
testcase_38 AC 12 ms
5,072 KB
testcase_39 AC 9 ms
4,384 KB
testcase_40 AC 10 ms
4,380 KB
testcase_41 AC 6 ms
4,380 KB
testcase_42 AC 17 ms
5,648 KB
testcase_43 AC 20 ms
6,020 KB
testcase_44 AC 26 ms
7,816 KB
testcase_45 AC 28 ms
7,708 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/*** author: yuji9511 ***/
#include <bits/stdc++.h>
// #include <atcoder/all>
// using namespace atcoder;
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
using vll = vector<ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
ostream& operator<<(ostream& os, lpair& h){ os << "(" << h.first << ", " << h.second << ")"; return os;}
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}

void solve(){
    ll n,m,p;
    cin >> n >> m >> p;
    vll a(n);
    rep(i,0,n) cin >> a[i];
    vll cnt_p(n, 0);
    vll b(n);
    rep(i,0,n){
        ll v = a[i];
        while(v % p == 0){
            v /= p;
            cnt_p[i]++;
        }
        b[i] = v;
    }
    rep(i,0,n){
        if(a[i] > m){
            print(1);
            return;
        }
    }
    bool ok = false;
    rep(i,0,n){
        if(b[i] != 1) ok = true;
    }

    if(not ok){
        print(-1);
        return;
    }
    ll max_val = 0;
    rep(i,0,n){
        max_val = max(max_val,a[i]);
    }

    ll ans = INF;
    rep(i,0,n){
        if(b[i] == 1) continue;
        ll res = 0, cur = 1;
        while(true){
            if(cur * max_val > m){
                res++;
                break;
            }else{
                cur *= b[i];
                res += 1 + cnt_p[i];
            }
        }
        ans = min(ans, res);

    }
    print(ans);




}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
}
0