結果

問題 No.1330 Multiply or Divide
ユーザー outlineoutline
提出日時 2021-01-08 22:37:23
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,923 bytes
コンパイル時間 1,341 ms
コンパイル使用メモリ 134,308 KB
実行使用メモリ 5,548 KB
最終ジャッジ日時 2023-08-10 12:32:02
合計ジャッジ時間 3,899 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 22 ms
5,472 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 16 ms
5,336 KB
testcase_07 AC 63 ms
5,548 KB
testcase_08 AC 29 ms
5,548 KB
testcase_09 AC 32 ms
5,436 KB
testcase_10 AC 28 ms
5,348 KB
testcase_11 AC 28 ms
5,352 KB
testcase_12 AC 29 ms
5,392 KB
testcase_13 AC 2 ms
4,384 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,384 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 25 ms
5,392 KB
testcase_19 AC 25 ms
5,392 KB
testcase_20 AC 25 ms
5,356 KB
testcase_21 AC 25 ms
5,348 KB
testcase_22 AC 25 ms
5,420 KB
testcase_23 AC 27 ms
5,360 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 1 ms
4,384 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,384 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 2 ms
4,384 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 19 ms
4,864 KB
testcase_35 AC 6 ms
4,380 KB
testcase_36 AC 17 ms
4,556 KB
testcase_37 AC 15 ms
4,552 KB
testcase_38 AC 10 ms
4,380 KB
testcase_39 AC 7 ms
4,384 KB
testcase_40 AC 9 ms
4,384 KB
testcase_41 AC 6 ms
4,380 KB
testcase_42 AC 15 ms
4,416 KB
testcase_43 AC 17 ms
4,820 KB
testcase_44 AC 21 ms
5,348 KB
testcase_45 AC 25 ms
5,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <array>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
using namespace std;

using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, m, p;
    cin >> n >> m >> p;
    vector<int> a(n), b(n), divcnt(n);
    int amax = 0;
    for(int i = 0; i < n; ++i){
        cin >> a[i];
        chmax(amax, a[i]);
        b[i] = a[i];
        while(b[i] % p == 0){
            b[i] /= p;
            divcnt[i] += 1;
        }
    }

    int ans = INF;
    for(int i = 0; i < n; ++i){
        if(a[i] > m){
            cout << 1 << endl;
            return 0;
        }
        if(b[i] == 1)   continue;
        ll prod = 1;
        int sum = 0;
        while(prod <= m){
            sum += 1;
            if(prod * amax > m){
                prod *= amax;
            }
            else if(prod * a[i] > m){
                prod *= a[i];
            }
            else{
                prod *= b[i];
                sum += divcnt[i];
            }
        }
        chmin(ans, sum);
    }
    
    if(ans == INF)  ans = -1;
    cout << ans << endl;

    return 0;
}
0