結果
問題 | No.1330 Multiply or Divide |
ユーザー |
![]() |
提出日時 | 2021-01-08 21:44:57 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,638 bytes |
コンパイル時間 | 676 ms |
コンパイル使用メモリ | 91,600 KB |
最終ジャッジ日時 | 2025-01-17 11:37:05 |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 45 WA * 1 |
ソースコード
#include <iostream> #include <algorithm> #include <iomanip> #include <vector> #include <queue> #include <set> #include <map> #include <cassert> #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; typedef long long ll; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; ll n, m, p; cin >> n >> m >> p; vector<ll> a(n); vector<ll> b(n); vector<ll> cnt(n); ll a_max = 0, b_max = 0; for(int i = 0; i < n; i++) { cin >> a[i]; b[i] = a[i]; while(b[i]%p == 0) { b[i] /= p; cnt[i]++; } chmax(a_max, a[i]); chmax(b_max, b[i]); } if(b_max == 1){ if(m > a_max){ cout << -1 << endl; return 0; }else{ cout << 1 << endl; return 0; } } if(a_max > m){ cout << 1 << endl; return 0; } int ans = 1e9; for(int i = 0; i < n; i++){ ll tmp = 1; int s = 0; if(b[i] == 1) continue; while(tmp <= m){ if(tmp*a_max > m) tmp *= a_max; else{ tmp *= b[i]; s += cnt[i]; } s++; } chmin(ans, s); } cout << ans << endl; }