結果

問題 No.1330 Multiply or Divide
ユーザー mtsdmtsd
提出日時 2021-01-08 21:41:29
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,880 bytes
コンパイル時間 1,367 ms
コンパイル使用メモリ 126,364 KB
実行使用メモリ 4,868 KB
最終ジャッジ日時 2023-08-10 12:25:44
合計ジャッジ時間 5,257 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 83 ms
4,692 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 33 ms
4,640 KB
testcase_07 AC 64 ms
4,600 KB
testcase_08 AC 115 ms
4,604 KB
testcase_09 AC 118 ms
4,660 KB
testcase_10 AC 115 ms
4,568 KB
testcase_11 AC 112 ms
4,868 KB
testcase_12 AC 115 ms
4,692 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 2 ms
4,384 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 100 ms
4,612 KB
testcase_19 AC 100 ms
4,632 KB
testcase_20 AC 100 ms
4,564 KB
testcase_21 AC 101 ms
4,568 KB
testcase_22 AC 101 ms
4,596 KB
testcase_23 AC 86 ms
4,696 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 2 ms
4,376 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 1 ms
4,376 KB
testcase_31 AC 1 ms
4,376 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 2 ms
4,380 KB
testcase_34 AC 76 ms
4,380 KB
testcase_35 AC 22 ms
4,380 KB
testcase_36 AC 67 ms
4,380 KB
testcase_37 AC 60 ms
4,380 KB
testcase_38 AC 38 ms
4,380 KB
testcase_39 AC 26 ms
4,376 KB
testcase_40 AC 31 ms
4,380 KB
testcase_41 AC 17 ms
4,380 KB
testcase_42 AC 55 ms
4,376 KB
testcase_43 AC 64 ms
4,380 KB
testcase_44 AC 33 ms
4,632 KB
testcase_45 AC 33 ms
4,572 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <iomanip>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
 
template<class T> inline bool chmax(T &a, T b){
    if(a<b){
        a = b;
        return true;
    }
    return false;
}

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

int main(){
    ll n,m,p;
    cin >> n >> m >> p;
    vector<ll>a(n);
    rep(i,n)cin >> a[i];
    sort(all(a));
    a.erase(unique(all(a)),a.end());
    ll mx = *max_element(all(a));
    int mi = inf;
    rep(i,a.size()){
        ll x = 1;
        set<ll>st;
        int res = 0;
        while(x<=m){
            if(res>mi)break;
            if(st.count(x))break;
            st.insert(x);
            if(x%p==0){
                x/=p;
                res++;
                continue;
            }
            if(x*mx > m){
                x*=mx;
                res++;
            }else{
                x*=a[i];
                res++;
            }
            
        }
        if(x>m)chmin(mi,res);
    }
    if(mi==inf){
        cout << -1 << endl;
    }else{
        cout << mi << endl;
    }
    return 0;
}
0