結果

問題 No.1330 Multiply or Divide
ユーザー Example0911
提出日時 2021-01-08 22:29:35
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 826 bytes
コンパイル時間 1,866 ms
コンパイル使用メモリ 200,628 KB
最終ジャッジ日時 2025-01-17 12:47:26
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 45 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = (1LL << 61);
ll mod = (ll)1e9 + 7;



signed main() {
	ll N, M, P; cin >> N >> M >> P;
	vector<ll>A(N); for (int i = 0; i < N; i++)cin >> A[i];
	vector<ll>B = A;
	vector<ll>cnt(N);
	ll ans = INF;
	bool ok = true;
	for (int i = 0; i < N; i++) {
		while (A[i] % P == 0) {
			A[i] /= P;
			cnt[i]++;
		}
	}
	sort(B.rbegin(), B.rend());
	for (int i = 0; i < N; i++) {
		if (B[i] > M) {
			ans = min(ans, 1LL);
		}
		ll x = 1;
		ll now = 0;
		ll l = 0;
		while (true) {
			if (x > M)break;
			now++;
			l++;
			if (l > 100) {
				now = INF; break;
			}
			if (l != 1) {
				x *= A[i];
				now += cnt[i];
			}
			else x *= B[0];
		}
		ans = min(ans, now);
	}
	
	if (ans != INF)cout << ans << endl;
	else cout << -1 << endl;
}
0