結果
| 問題 |
No.1330 Multiply or Divide
|
| コンテスト | |
| ユーザー |
lorent_kyopro
|
| 提出日時 | 2021-01-09 12:15:54 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,157 bytes |
| コンパイル時間 | 2,840 ms |
| コンパイル使用メモリ | 202,584 KB |
| 最終ジャッジ日時 | 2025-01-17 15:32:32 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 44 WA * 2 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
__attribute__((constructor))
void fast_io() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
}
int main() {
int n, m, p;
cin >> n >> m >> p;
vector<int> a(n);
for (auto& ai : a) cin >> ai;
int mx = *max_element(a.begin(), a.end());
if (mx > m) {
cout << 1 << '\n';
return 0;
}
m = (m + mx - 1) / mx;
vector<int> cnt(n);
for (int i = 0; i < n; ++i) {
while (a[i] % p == 0) {
a[i] /= p;
cnt[i]++;
}
}
if (all_of(a.begin(), a.end(), [](int x) { return x == 1; })) {
cout << -1 << '\n';
return 0;
}
map<int, int> mp;
for (int i = 0; i < n; ++i) {
if (mp.count(cnt[i])) {
mp[cnt[i]] = max(mp[cnt[i]], a[i]);
} else {
mp[cnt[i]] = a[i];
}
}
vector<int> dp(10000, 1);
for (int i = 0; i < 1000; ++i) {
if (dp[i] >= m) {
cout << i + 1 << '\n';
return 0;
}
for (auto [cost, x] : mp) {
dp[i + cost + 1] = max(dp[i + cost + 1], dp[i] * x);
}
}
}
lorent_kyopro