結果

問題 No.1330 Multiply or Divide
ユーザー Example0911Example0911
提出日時 2021-01-09 10:01:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 136 ms / 2,000 ms
コード長 853 bytes
コンパイル時間 2,214 ms
コンパイル使用メモリ 204,600 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-28 17:14:35
合計ジャッジ時間 5,648 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 70 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 39 ms
5,376 KB
testcase_07 AC 136 ms
5,376 KB
testcase_08 AC 88 ms
5,376 KB
testcase_09 AC 91 ms
5,376 KB
testcase_10 AC 87 ms
5,376 KB
testcase_11 AC 85 ms
5,376 KB
testcase_12 AC 88 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 84 ms
5,376 KB
testcase_19 AC 84 ms
5,376 KB
testcase_20 AC 83 ms
5,376 KB
testcase_21 AC 83 ms
5,376 KB
testcase_22 AC 83 ms
5,376 KB
testcase_23 AC 90 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 1 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 2 ms
5,376 KB
testcase_31 AC 2 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 2 ms
5,376 KB
testcase_34 AC 62 ms
5,376 KB
testcase_35 AC 19 ms
5,376 KB
testcase_36 AC 55 ms
5,376 KB
testcase_37 AC 50 ms
5,376 KB
testcase_38 AC 33 ms
5,376 KB
testcase_39 AC 22 ms
5,376 KB
testcase_40 AC 27 ms
5,376 KB
testcase_41 AC 15 ms
5,376 KB
testcase_42 AC 46 ms
5,376 KB
testcase_43 AC 53 ms
5,376 KB
testcase_44 AC 39 ms
5,376 KB
testcase_45 AC 39 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

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;

// i回操作をするときのxの値の最大値
ll dp[100010];
signed main() {
	ll N, M, P; cin >> N >> M >> P;
	vector<ll>A(N); for (int i = 0; i < N; i++)cin >> A[i];
	// 最後に掛けることができる
	ll t = 0;
	for (int i = 0; i < N; i++)t = max(t, A[i]);
	// 割る操作をi回するときの最大値
	vector<ll>m(62, 1);
	for (int i = 0; i < N; i++) {
		ll cnt = 0;
		while (A[i] % P == 0) {
			A[i] /= P;
			cnt++;
		}
		m[cnt] = max(m[cnt], A[i]);
	}
	dp[0] = 1;
	for (int i = 0; i < 10010; i++) {
		if (dp[i] * t > M) {
			cout << i + 1 << endl; return 0;
		}
		for (int j = 0; j <= 60; j++) {
			// 遷移
			dp[i + j + 1] = max(dp[i + j + 1], dp[i] * m[j]);
		}
	}
	cout << -1 << endl;
}
0