結果

問題 No.1330 Multiply or Divide
ユーザー nok0nok0
提出日時 2020-10-30 16:15:20
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 727 bytes
コンパイル時間 2,211 ms
コンパイル使用メモリ 206,832 KB
実行使用メモリ 5,548 KB
最終ジャッジ日時 2023-09-29 04:25:26
合計ジャッジ時間 6,234 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 69 ms
5,392 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 40 ms
5,468 KB
testcase_07 AC 102 ms
5,380 KB
testcase_08 AC 111 ms
5,340 KB
testcase_09 AC 115 ms
5,412 KB
testcase_10 AC 111 ms
5,340 KB
testcase_11 AC 110 ms
5,452 KB
testcase_12 AC 111 ms
5,484 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 109 ms
5,400 KB
testcase_19 AC 109 ms
5,340 KB
testcase_20 AC 109 ms
5,404 KB
testcase_21 AC 110 ms
5,400 KB
testcase_22 AC 109 ms
5,472 KB
testcase_23 AC 90 ms
5,348 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 1 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 1 ms
4,376 KB
testcase_29 AC 2 ms
4,376 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 81 ms
4,944 KB
testcase_35 AC 23 ms
4,376 KB
testcase_36 AC 72 ms
4,784 KB
testcase_37 AC 64 ms
4,376 KB
testcase_38 AC 40 ms
4,376 KB
testcase_39 AC 28 ms
4,380 KB
testcase_40 AC 34 ms
4,376 KB
testcase_41 AC 17 ms
4,376 KB
testcase_42 AC 59 ms
4,424 KB
testcase_43 AC 68 ms
4,620 KB
testcase_44 AC 40 ms
5,532 KB
testcase_45 AC 39 ms
5,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using pii = pair<int, int>;
#define REP(i, x) for(int i = 0; i < (x); i++)

ll res, x = 1;

int main() {
	int n, m, p;
	cin >> n >> m >> p;
	vector a(n, 0);
	REP(i, n) { cin >> a[i]; }

	int amax = *max_element(a.begin(), a.end());

	vector<pii> b(n);
	REP(i, n) {
		int num = 1;
		while(a[i] % p == 0) a[i] /= p, num++;
		b[i] = pii(a[i], num);
	}

	auto f = [](pii a, pii b) {
		return a.first / (double)a.second < b.first / (double)b.second;
	};

	sort(b.rbegin(), b.rend(), f);

	if(amax <= m and b[0].first == 1) {
		puts("-1");
		return 0;
	}

	int lim = m / amax + 1;

	while(x < lim) x *= b[0].first, res += b[0].second;
	
	printf("%d\n", res + 1);
}
0