結果

問題 No.1330 Multiply or Divide
ユーザー firiexpfiriexp
提出日時 2021-01-08 21:52:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,903 bytes
コンパイル時間 1,075 ms
コンパイル使用メモリ 104,600 KB
実行使用メモリ 4,932 KB
最終ジャッジ日時 2023-08-10 09:19:05
合計ジャッジ時間 3,734 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 2 ms
4,376 KB
testcase_05 WA -
testcase_06 AC 19 ms
4,892 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

template <class T, class U>
vector<T> make_v(U size, const T& init){ return vector<T>(static_cast<size_t>(size), init); }

template<class... Ts, class U>
auto make_v(U size, Ts... rest) { return vector<decltype(make_v(rest...))>(static_cast<size_t>(size), make_v(rest...)); }

template<class T> void chmin(T &a, const T &b){ a = (a < b ? a : b); }
template<class T> void chmax(T &a, const T &b){ a = (a > b ? a : b); }

int main() {
    int n, m, p;
    cin >> n >> m >> p;
    vector<int> a(n);
    vector<int> b(n);
    for (auto &&i : a) scanf("%d", &i);
    int X = 0;
    for (int i = 0; i < n; ++i) {
        while(a[i]%p == 0) {
            a[i] /= p;
            b[i]++;
        }
        X = max(X, b[i]);
    }
    auto x = *max_element(a.begin(),a.end());
    if(x == 1) {
        puts("-1");
        return 0;
    }
    vector<int> mx(X+1, 0);
    for (int i = 0; i < n; ++i) {
        chmax(mx[b[i]], a[i]);
    }
    vector<int> mae(X+1, 0);
    for (int i = 0; i <= X; ++i) {
        if(mx[i] == 0) continue;
        mae[i] = mx[i];
        for (int j = 0; j < X; ++j) {
            mae[i] *= p;
        }
    }
    vector<ll> dp(10000, 1);
    int ans = INF<int>;
    for (int i = 0; i < 10000; ++i) {
        if(dp[i] >= m){
            ans = min(ans, i);
            cout << ans << "\n";
            return 0;
        }
        for (int j = 0; j <= X; ++j) {
            if(dp[i]*mae[j] >= m) chmin(ans, i+1);
            chmax(dp[i+j+1], dp[i]*mx[j]);
        }
        cout << i << "\n";
    }
    return 0;
}
0