結果

問題 No.1330 Multiply or Divide
ユーザー milanis48663220milanis48663220
提出日時 2021-01-08 21:44:57
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,638 bytes
コンパイル時間 817 ms
コンパイル使用メモリ 97,532 KB
実行使用メモリ 7,932 KB
最終ジャッジ日時 2023-08-10 12:26:13
合計ジャッジ時間 3,596 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 27 ms
7,724 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 22 ms
7,736 KB
testcase_07 AC 103 ms
7,856 KB
testcase_08 AC 35 ms
7,844 KB
testcase_09 AC 39 ms
7,724 KB
testcase_10 AC 35 ms
7,860 KB
testcase_11 AC 33 ms
7,892 KB
testcase_12 AC 35 ms
7,840 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,388 KB
testcase_17 AC 1 ms
4,384 KB
testcase_18 AC 30 ms
7,720 KB
testcase_19 AC 31 ms
7,768 KB
testcase_20 AC 30 ms
7,840 KB
testcase_21 AC 31 ms
7,796 KB
testcase_22 AC 30 ms
7,732 KB
testcase_23 AC 32 ms
7,736 KB
testcase_24 AC 1 ms
4,384 KB
testcase_25 AC 1 ms
4,384 KB
testcase_26 AC 2 ms
4,384 KB
testcase_27 AC 2 ms
4,380 KB
testcase_28 AC 2 ms
4,384 KB
testcase_29 AC 2 ms
4,384 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 2 ms
4,384 KB
testcase_32 AC 2 ms
4,384 KB
testcase_33 AC 1 ms
4,384 KB
testcase_34 AC 23 ms
6,516 KB
testcase_35 AC 8 ms
4,380 KB
testcase_36 AC 20 ms
6,192 KB
testcase_37 AC 19 ms
5,988 KB
testcase_38 AC 12 ms
4,956 KB
testcase_39 AC 9 ms
4,384 KB
testcase_40 AC 11 ms
4,692 KB
testcase_41 AC 6 ms
4,380 KB
testcase_42 AC 17 ms
5,664 KB
testcase_43 AC 20 ms
5,900 KB
testcase_44 AC 27 ms
7,724 KB
testcase_45 AC 29 ms
7,932 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cassert>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    ll n, m, p; cin >> n >> m >> p;
    vector<ll> a(n);
    vector<ll> b(n);
    vector<ll> cnt(n);
    ll a_max = 0, b_max = 0;
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        b[i] = a[i];
        while(b[i]%p == 0) {
            b[i] /= p;
            cnt[i]++;
        }
        chmax(a_max, a[i]);
        chmax(b_max, b[i]);
    }
    if(b_max == 1){
        if(m > a_max){
            cout << -1 << endl;
            return 0;
        }else{
            cout << 1 << endl;
            return 0;
        }
    }
    if(a_max > m){
        cout << 1 << endl;
        return 0;
    }
    int ans = 1e9;
    for(int i = 0; i < n; i++){
        ll tmp = 1;
        int s = 0;
        if(b[i] == 1) continue;
        while(tmp <= m){
            if(tmp*a_max > m) tmp *= a_max;
            else{
                tmp *= b[i];
                s += cnt[i];
            }
            s++;
        }
        chmin(ans, s);
    }
    
    cout << ans << endl;
}
0