結果

問題 No.1330 Multiply or Divide
ユーザー mtsdmtsd
提出日時 2021-01-08 21:35:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,873 bytes
コンパイル時間 1,285 ms
コンパイル使用メモリ 126,156 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-28 02:16:02
合計ジャッジ時間 4,711 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 2 ms
6,944 KB
testcase_05 WA -
testcase_06 AC 34 ms
6,940 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 <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,n){
        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