結果

問題 No.1330 Multiply or Divide
ユーザー chocono2230chocono2230
提出日時 2021-01-08 22:28:42
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,251 bytes
コンパイル時間 2,287 ms
コンパイル使用メモリ 202,772 KB
実行使用メモリ 5,344 KB
最終ジャッジ日時 2023-08-10 12:30:29
合計ジャッジ時間 5,810 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 64 ms
5,156 KB
testcase_02 WA -
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 29 ms
4,380 KB
testcase_07 AC 99 ms
5,200 KB
testcase_08 AC 80 ms
5,104 KB
testcase_09 AC 82 ms
5,068 KB
testcase_10 AC 80 ms
5,068 KB
testcase_11 AC 78 ms
5,096 KB
testcase_12 AC 80 ms
5,048 KB
testcase_13 AC 1 ms
4,384 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 76 ms
5,056 KB
testcase_19 AC 75 ms
5,096 KB
testcase_20 AC 76 ms
5,088 KB
testcase_21 AC 75 ms
5,344 KB
testcase_22 AC 76 ms
5,160 KB
testcase_23 AC 83 ms
5,088 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 1 ms
4,380 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 2 ms
4,384 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 59 ms
5,204 KB
testcase_35 AC 17 ms
4,376 KB
testcase_36 AC 51 ms
5,068 KB
testcase_37 AC 46 ms
4,380 KB
testcase_38 AC 29 ms
4,380 KB
testcase_39 AC 21 ms
4,376 KB
testcase_40 AC 24 ms
4,376 KB
testcase_41 AC 13 ms
4,380 KB
testcase_42 AC 42 ms
4,380 KB
testcase_43 AC 48 ms
4,380 KB
testcase_44 AC 35 ms
5,120 KB
testcase_45 AC 36 ms
5,124 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

pair<ll, ll> fc(int a, int p){
  int res = 1;
  while(a % p == 0){
    res++;
    a /= p;
  }
  return {a, res};
}

int main(){
  int n, m, p;
  cin >> n >> m >> p;
  if(m == 1){
    cout << 0 << endl;
    return 0;
  }
  ll now = 1;
  vector<pair<int, int>> ab;
  rep(i, n){
    int in;
    cin >> in;
    now = max((int)now, in);
    auto [a, b] = fc(in, p);
    // cerr << a << " " << b << endl;
    if(a != 1){
      ab.push_back({a, b});
    }
  }
  int ans = 1001001001;
  if(now <= m){
    for(auto [a, b] : ab){
      ll nw = now;
      int add = 1;
      while(nw <= m){
        nw *= a;
        add += b;
      }
      ans = min(ans, add);
    }
  }
  if(now > m){
    ans = 1;
  }else if(ab.size() == 0) ans = -1;
  cout << ans << endl;
  return 0;
}
0