結果

問題 No.1330 Multiply or Divide
ユーザー lorent_kyopro
提出日時 2021-01-09 12:20:49
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,163 bytes
コンパイル時間 2,762 ms
コンパイル使用メモリ 203,568 KB
最終ジャッジ日時 2025-01-17 15:33:03
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 44 WA * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

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

__attribute__((constructor))
void fast_io() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

int main() {
    int n, m, p;
    cin >> n >> m >> p;
    vector<int> a(n);
    for (auto& ai : a) cin >> ai;

    int mx = *max_element(a.begin(), a.end());
    if (mx > m) {
        cout << 1 << '\n';
        return 0;
    }
    m = (m + mx - 1) / mx;

    vector<int> cnt(n);
    for (int i = 0; i < n; ++i) {
        while (a[i] % p == 0) {
            a[i] /= p;
            cnt[i]++;
        }
    }
    if (all_of(a.begin(), a.end(), [](int x) { return x == 1; })) {
        cout << -1 << '\n';
        return 0;
    }

    map<int, int> mp;
    for (int i = 0; i < n; ++i) {
        if (mp.count(cnt[i])) {
            mp[cnt[i]] = max(mp[cnt[i]], a[i]);
        } else {
            mp[cnt[i]] = a[i];
        }
    }

    vector<long long> dp(10000, 1);
    for (int i = 0; i < 1000; ++i) {
        if (dp[i] >= m) {
            cout << i + 1 << '\n';
            return 0;
        }
        for (auto [cost, x] : mp) {
            dp[i + cost + 1] = max(dp[i + cost + 1], dp[i] * x);
        }
    }
}
0