結果

問題 No.1330 Multiply or Divide
ユーザー MTGSMTGS
提出日時 2021-01-09 00:10:53
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 128 ms / 2,000 ms
コード長 952 bytes
コンパイル時間 1,671 ms
コンパイル使用メモリ 167,916 KB
実行使用メモリ 4,920 KB
最終ジャッジ日時 2023-08-10 13:14:23
合計ジャッジ時間 5,261 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 63 ms
4,636 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 34 ms
4,632 KB
testcase_07 AC 128 ms
4,624 KB
testcase_08 AC 78 ms
4,920 KB
testcase_09 AC 80 ms
4,624 KB
testcase_10 AC 80 ms
4,684 KB
testcase_11 AC 79 ms
4,708 KB
testcase_12 AC 82 ms
4,608 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,384 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,384 KB
testcase_18 AC 78 ms
4,592 KB
testcase_19 AC 79 ms
4,576 KB
testcase_20 AC 79 ms
4,864 KB
testcase_21 AC 77 ms
4,896 KB
testcase_22 AC 77 ms
4,728 KB
testcase_23 AC 83 ms
4,580 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,384 KB
testcase_28 AC 2 ms
4,384 KB
testcase_29 AC 0 ms
4,380 KB
testcase_30 AC 2 ms
4,384 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 1 ms
4,384 KB
testcase_34 AC 58 ms
4,384 KB
testcase_35 AC 17 ms
4,380 KB
testcase_36 AC 51 ms
4,384 KB
testcase_37 AC 45 ms
4,384 KB
testcase_38 AC 30 ms
4,380 KB
testcase_39 AC 21 ms
4,384 KB
testcase_40 AC 25 ms
4,380 KB
testcase_41 AC 13 ms
4,380 KB
testcase_42 AC 42 ms
4,384 KB
testcase_43 AC 48 ms
4,380 KB
testcase_44 AC 35 ms
4,704 KB
testcase_45 AC 35 ms
4,624 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using ll = long long;
using P = pair<ll,ll>;
using PP = pair<P,ll>;
using vec = vector<ll>;
using vecp = vector<P>;
using mat = vector<vec>;
using matp = vector<vecp>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define all(v) v.begin(), v.end()




int main(){
  ll N,M,P,m=0;
  cin >> N >> M >> P;
  vec A(N),B(30,0);
  rep(i,N){
    cin >> A.at(i);
    m=max(m,A.at(i));
    ll t=0;
    while(A.at(i)%P==0){
      t++;
      A.at(i)/=P;
    }
    B.at(t)=max(B.at(t),A.at(i));
  }
  if(m>M){
    cout << 1 << endl;
    return 0;
  }
  rep(i,30){
    if(B.at(i)>1){
      break;
    }
    if(i==29){
      cout << -1 << endl;
      return 0;
    }
  }
  vec dp(900,0);
  dp.at(0)=1;
  rep(i,900){
    if(dp.at(i)*m>M){
      cout << i+1 << endl;
      return 0;
    }
    rep(j,30){
      dp.at(i+j+1)=max(dp.at(i+j+1),dp.at(i)*B.at(j));
    }
  }
  
}
0