結果

問題 No.1330 Multiply or Divide
ユーザー norikamenorikame
提出日時 2021-01-08 22:14:26
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 136 ms / 2,000 ms
コード長 2,289 bytes
コンパイル時間 2,443 ms
コンパイル使用メモリ 217,896 KB
実行使用メモリ 7,776 KB
最終ジャッジ日時 2023-08-10 13:07:16
合計ジャッジ時間 6,097 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 69 ms
6,756 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 42 ms
6,744 KB
testcase_07 AC 136 ms
6,684 KB
testcase_08 AC 100 ms
7,652 KB
testcase_09 AC 100 ms
6,792 KB
testcase_10 AC 97 ms
7,472 KB
testcase_11 AC 95 ms
7,052 KB
testcase_12 AC 100 ms
7,776 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 73 ms
4,636 KB
testcase_19 AC 70 ms
4,580 KB
testcase_20 AC 72 ms
4,748 KB
testcase_21 AC 76 ms
4,748 KB
testcase_22 AC 73 ms
4,576 KB
testcase_23 AC 86 ms
6,740 KB
testcase_24 AC 2 ms
4,380 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 2 ms
4,376 KB
testcase_29 AC 1 ms
4,380 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 56 ms
4,380 KB
testcase_35 AC 17 ms
4,380 KB
testcase_36 AC 50 ms
4,380 KB
testcase_37 AC 45 ms
4,376 KB
testcase_38 AC 30 ms
4,380 KB
testcase_39 AC 21 ms
4,380 KB
testcase_40 AC 25 ms
4,380 KB
testcase_41 AC 14 ms
4,376 KB
testcase_42 AC 41 ms
4,380 KB
testcase_43 AC 49 ms
4,384 KB
testcase_44 AC 43 ms
6,680 KB
testcase_45 AC 41 ms
6,628 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ull = unsigned long long;
#define v(t) vector<t>
#define p(t) pair<t, t>
#define p2(t, s) pair<t, s>
#define vp(t) v(p(t))

#define rep(i, n) for (int i=0,i##_len=((int)(n)); i<i##_len; ++i)
#define rep2(i, a, n) for (int i=((int)(a)),i##_len=((int)(n)); i<=i##_len; ++i)
#define repr(i, n) for (int i=((int)(n)-1); i>=0; --i)
#define rep2r(i, a, n) for (int i=((int)(n)),i##_len=((int)(a)); i>=i##_len; --i)

#define repi(itr, c) for (__typeof((c).begin()) itr=(c).begin(); itr!=(c).end(); ++itr)
#define repir(itr, c) for (__typeof((c).rbegin()) itr=(c).rbegin(); itr!=(c).rend(); ++itr)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define eb emplace_back

#define INF (1e9)
#define LINF (1e18)
#define PI (acos(-1))
#define EPS (1e-7)
#define DEPS (1e-10)

int main(){
    int n;
    ll m, p;
    cin >> n >> m >> p;
    v(ll) a(n);
    rep(i, n) cin >> a[i];
    ll mval = 0;
    rep(i, n) mval = max(mval, a[i]);
    if (mval > m) {
        cout << 1 << endl;
        return 0;
    }
    map<int, v(ll)> b;
    rep(i, n) {
        int cnt = 0;
        while (a[i]%p == 0) {
            a[i] /= p;
            ++cnt;
        }
        b[cnt].pb(a[i]);
    }
    repi(itr, b) RSORT(itr->second);
    bool one = true;
    repi(itr, b) if (itr->second[0] > 1) one = false;
    if (one) {
        cout << -1 << endl;
        return 0;
    }
    priority_queue<p2(int,ll), v(p2(int,ll)), greater<p2(int,ll)>> que;
    repi(itr, b) {
        if (itr->second[0] <= 1) continue;
        que.emplace(1+itr->first, -(itr->second[0]));
    }
    while (!que.empty()) {
        auto tp = que.top(); que.pop();
        int cnt = tp.first;
        ll val = tp.second * -1;
        if (val*mval > m) {
            cout << (cnt+1) << endl;
            return 0;
        }
        repi(itr, b) {
            if (itr->second[0] <= 1) continue;
            que.emplace(1+cnt+(itr->first), val*(itr->second[0])*(-1));
        }
    }
    return 0;
}
0