結果

問題 No.1330 Multiply or Divide
ユーザー どらら
提出日時 2021-01-09 20:30:43
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 132 ms / 2,000 ms
コード長 923 bytes
コンパイル時間 1,427 ms
コンパイル使用メモリ 170,276 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2025-06-20 01:25:57
合計ジャッジ時間 4,563 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 51
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  ll N, M, P;
  cin >> N >> M >> P;

  vector<ll> v(N);
  ll mx_v = 0;
  rep(i,N){
    cin >> v[i];
    mx_v = max(mx_v, v[i]);
  }

  map<ll,ll> memo;
  rep(i,N){
    ll cnt = 1;
    ll x = v[i];
    while(x%P==0){
      x /= P;
      cnt++;
    }
    memo[cnt] = max(memo[cnt], x);
  }

  vector<ll> dp(10000,0);
  dp[0] = 1;
  rep(i,dp.size()){
    if(dp[i] * mx_v > M){
      cout << i + 1 << endl;
      return 0;
    }
    FOR(it,memo){
      if(i + it->first >= dp.size()) continue;
      dp[i + it->first] = max(dp[i + it->first], it->second * dp[i]);
    }
  }

  cout << -1 << endl;

  return 0;
}

0