結果

問題 No.1330 Multiply or Divide
ユーザー 00 Sakuda00 Sakuda
提出日時 2024-04-02 03:11:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,228 bytes
コンパイル時間 2,244 ms
コンパイル使用メモリ 205,916 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-04-02 03:11:37
合計ジャッジ時間 5,384 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 66 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 1 ms
6,676 KB
testcase_05 AC 3 ms
6,676 KB
testcase_06 AC 37 ms
6,676 KB
testcase_07 WA -
testcase_08 AC 82 ms
6,676 KB
testcase_09 AC 88 ms
6,676 KB
testcase_10 AC 85 ms
6,676 KB
testcase_11 AC 83 ms
6,676 KB
testcase_12 AC 85 ms
6,676 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 2 ms
6,676 KB
testcase_15 AC 2 ms
6,676 KB
testcase_16 AC 2 ms
6,676 KB
testcase_17 AC 2 ms
6,676 KB
testcase_18 AC 2 ms
6,676 KB
testcase_19 AC 2 ms
6,676 KB
testcase_20 AC 1 ms
6,676 KB
testcase_21 AC 2 ms
6,676 KB
testcase_22 AC 2 ms
6,676 KB
testcase_23 AC 85 ms
6,676 KB
testcase_24 AC 2 ms
6,676 KB
testcase_25 AC 2 ms
6,676 KB
testcase_26 AC 2 ms
6,676 KB
testcase_27 AC 1 ms
6,676 KB
testcase_28 AC 2 ms
6,676 KB
testcase_29 AC 2 ms
6,676 KB
testcase_30 AC 2 ms
6,676 KB
testcase_31 AC 1 ms
6,676 KB
testcase_32 AC 1 ms
6,676 KB
testcase_33 AC 2 ms
6,676 KB
testcase_34 AC 1 ms
6,676 KB
testcase_35 AC 4 ms
6,676 KB
testcase_36 AC 2 ms
6,676 KB
testcase_37 AC 2 ms
6,676 KB
testcase_38 AC 2 ms
6,676 KB
testcase_39 AC 2 ms
6,676 KB
testcase_40 AC 2 ms
6,676 KB
testcase_41 AC 2 ms
6,676 KB
testcase_42 AC 2 ms
6,676 KB
testcase_43 AC 2 ms
6,676 KB
testcase_44 WA -
testcase_45 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/modint>
using namespace atcoder;
using namespace std;
using ll = long long;
using mint = modint998244353;
int main() {
	int N;ll M, P;cin >> N >> M >> P;
	int K = 12;
	vector<ll> A(K + 1, 0);
	bool ret = false;
	for (int i = 1;i <= N;i++) {
		ll a;cin >> a;
		if (a > M) {
			cout << 1 << endl;
			return 0;
		}
		int c = 0;
		while (a % P == 0) {
			c++;
			a /= P;
		}
		A[c] = max(A[c], a);
		if (a != 1) {
			ret = true;
		}
	}
	if (!ret) {
		cout << -1 << endl;
		return 0;
	}
	vector<ll> dp(K + 1, 1);
	ll ep = 1;
	for (int i = 0;i <= K;i++) {
		if (A[i] == 0) {
			if (ep > M) continue;
			ep *= P;
			continue;
		}
		vector<ll> ndp(K + 1, 1);
		ll x = A[i];
		ll y = ep * A[i];
		for (int j = 1;j <= K;j++) {
			//iをつかわない
			ndp[j] = dp[j];
			if (dp[j] == M + 1) continue;
			//iをつかう
			//いっかいかけるでoverになるばあい
			if (y * ndp[j - 1] > M) {
				ndp[j] = M + 1;
				continue;
			}
			//ならなかったばあい
			if (i + 1 <= j) {
				ndp[j] = max(ndp[j], min(M + 1, x * ndp[j - i - 1]));
			}
		}
		swap(dp, ndp);
		ep *= P;
	}
	for (int i = 1;i <= K;i++) {
		if (dp[i] == M + 1) {
			cout << i << endl;
			return 0;
		}
	}
	
}
0