結果

問題 No.1330 Multiply or Divide
ユーザー 👑 hitonanodehitonanode
提出日時 2021-01-08 22:21:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 92 ms / 2,000 ms
コード長 1,202 bytes
コンパイル時間 2,192 ms
コンパイル使用メモリ 208,872 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-28 06:22:16
合計ジャッジ時間 4,393 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 23 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 18 ms
5,376 KB
testcase_07 AC 92 ms
5,376 KB
testcase_08 AC 30 ms
5,376 KB
testcase_09 AC 34 ms
5,376 KB
testcase_10 AC 29 ms
5,376 KB
testcase_11 AC 28 ms
5,376 KB
testcase_12 AC 29 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 26 ms
5,376 KB
testcase_19 AC 26 ms
5,376 KB
testcase_20 AC 26 ms
5,376 KB
testcase_21 AC 26 ms
5,376 KB
testcase_22 AC 25 ms
5,376 KB
testcase_23 AC 27 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 2 ms
5,376 KB
testcase_31 AC 2 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 2 ms
5,376 KB
testcase_34 AC 20 ms
5,376 KB
testcase_35 AC 6 ms
5,376 KB
testcase_36 AC 18 ms
5,376 KB
testcase_37 AC 16 ms
5,376 KB
testcase_38 AC 11 ms
5,376 KB
testcase_39 AC 8 ms
5,376 KB
testcase_40 AC 9 ms
5,376 KB
testcase_41 AC 6 ms
5,376 KB
testcase_42 AC 15 ms
5,376 KB
testcase_43 AC 17 ms
5,376 KB
testcase_44 AC 19 ms
5,376 KB
testcase_45 AC 19 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using plint = pair<lint, lint>;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define REP(i, n) FOR(i,0,n)
template <typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }


void answer(lint x) {
    cout << x << '\n';
    exit(0);
}

int main()
{
    cin.tie(nullptr), ios::sync_with_stdio(false);
    int N, M, P;
    cin >> N >> M >> P;
    lint maxi = 0;

    vector<plint> te2w;

    vector<lint> te2amax(32, 0);
    while (N--) {
        lint a;
        cin >> a;
        chmax(maxi, a);
        int te = 1;
        while (a % P == 0) a /= P, te++;
        chmax(te2amax[te], a);
    }
    FOR(t, 1, te2amax.size()) if (te2amax[t] > 1) te2w.emplace_back(t, te2amax[t]);

    const lint tgt = (M + 1 + maxi - 1) / maxi;

    priority_queue<plint, vector<plint>, greater<plint>> pq;
    pq.emplace(1, -1);
    while (pq.size()) {
        auto [D, val] = pq.top();
        pq.pop();
        if (abs(val) >= tgt) {
            answer(D);
        }
        for (auto [dd, a] : te2w) {
            pq.emplace(D + dd, val * a);
        }
    }
    puts("-1");
}
0