結果

問題 No.1330 Multiply or Divide
ユーザー kkktymkkktym
提出日時 2021-01-08 22:32:49
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 132 ms / 2,000 ms
コード長 1,587 bytes
コンパイル時間 2,265 ms
コンパイル使用メモリ 115,672 KB
実行使用メモリ 4,832 KB
最終ジャッジ日時 2023-08-10 13:09:30
合計ジャッジ時間 5,033 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 65 ms
4,832 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 36 ms
4,612 KB
testcase_07 AC 132 ms
4,748 KB
testcase_08 AC 82 ms
4,604 KB
testcase_09 AC 87 ms
4,608 KB
testcase_10 AC 82 ms
4,648 KB
testcase_11 AC 79 ms
4,632 KB
testcase_12 AC 82 ms
4,664 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 78 ms
4,604 KB
testcase_19 AC 78 ms
4,616 KB
testcase_20 AC 77 ms
4,608 KB
testcase_21 AC 77 ms
4,564 KB
testcase_22 AC 78 ms
4,788 KB
testcase_23 AC 84 ms
4,636 KB
testcase_24 AC 2 ms
4,384 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 1 ms
4,376 KB
testcase_30 AC 1 ms
4,380 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 58 ms
4,380 KB
testcase_35 AC 17 ms
4,504 KB
testcase_36 AC 52 ms
4,380 KB
testcase_37 AC 46 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,380 KB
testcase_42 AC 43 ms
4,388 KB
testcase_43 AC 50 ms
4,384 KB
testcase_44 AC 36 ms
4,788 KB
testcase_45 AC 36 ms
4,636 KB
権限があれば一括ダウンロードができます

ソースコード

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();
    rep(i,40) {
      if(c[i] == 0) continue;
      if(num*a[id[i]] >= m+1) {
	if(d[m+1] == 0 || d[m+1] > dd+1) {
	  d[m+1] = dd+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]-1 << "\n";
  
  return 0;
}
0