結果

問題 No.1330 Multiply or Divide
ユーザー kkktymkkktym
提出日時 2021-01-08 22:25:13
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,625 bytes
コンパイル時間 1,206 ms
コンパイル使用メモリ 117,500 KB
実行使用メモリ 4,872 KB
最終ジャッジ日時 2023-08-10 10:21:33
合計ジャッジ時間 5,238 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 65 ms
4,556 KB
testcase_02 WA -
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 37 ms
4,836 KB
testcase_07 WA -
testcase_08 AC 83 ms
4,684 KB
testcase_09 AC 87 ms
4,840 KB
testcase_10 AC 83 ms
4,588 KB
testcase_11 AC 81 ms
4,552 KB
testcase_12 AC 83 ms
4,872 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 2 ms
4,380 KB
testcase_17 WA -
testcase_18 AC 79 ms
4,552 KB
testcase_19 AC 79 ms
4,828 KB
testcase_20 AC 79 ms
4,556 KB
testcase_21 AC 79 ms
4,552 KB
testcase_22 AC 79 ms
4,604 KB
testcase_23 WA -
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 WA -
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 1 ms
4,384 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 2 ms
4,376 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 59 ms
4,376 KB
testcase_35 AC 17 ms
4,376 KB
testcase_36 AC 52 ms
4,380 KB
testcase_37 AC 47 ms
4,380 KB
testcase_38 AC 30 ms
4,380 KB
testcase_39 AC 21 ms
4,380 KB
testcase_40 AC 25 ms
4,380 KB
testcase_41 AC 14 ms
4,384 KB
testcase_42 AC 43 ms
4,376 KB
testcase_43 AC 50 ms
4,376 KB
testcase_44 WA -
testcase_45 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <cstdio>
#include <limits>
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; }
template<class T> inline int  sz(T &a) { return a.size(); }
using ll = long long; using ld = long double;
using pi = pair<int,int>; using pl = pair<ll,ll>;
using vi = vector<int>; using vvi = vector<vi>;
using vl = vector<ll>; using vvl = vector<vl>;
const int inf = numeric_limits<int>::max();
const ll infll = numeric_limits<ll>::max();
int main()
{
  ll n,m,p; cin >> n >> m >> p;
  vl a(n);
  rep(i,n) cin >> a[i];

  vl c(40, 0);
  vi id(40, -1);
  rep(i,n) {
    int cnt = 0;
    ll tmp = a[i];
    while(tmp % p == 0) {
      tmp /= p;
      cnt++;
    }
    if(chmax(c[cnt], tmp)) {
      id[cnt] = i;
    }
  }

  priority_queue<pl, vector<pl>, greater<pl>> pq;
  map<ll,ll> d;
  d[1] = 1;
  pq.push({1, 1});
  while(!pq.empty()) {
    auto [dd, num] = pq.top(); pq.pop();
    //    cout << dd << ":" << num << "\n";
    rep(i,40) {
      if(c[i] <= 0) continue;
      if(num*a[id[i]] >= m) {
	if(d[m] == 0 || d[m] > dd+i+1) {
	  d[m] = dd+i+1;
	}
      }
      else if(d[num*c[i]] == 0 || d[num*c[i]] > dd+i+1) {
	d[num*c[i]] = dd+i+1;
	pq.push({dd+i+1, num*c[i]});
      }
    }
  }

  cout << d[m]-1 << "\n";
  
  return 0;
}
0