結果
問題 |
No.1330 Multiply or Divide
|
ユーザー |
![]() |
提出日時 | 2021-01-09 12:45:22 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 61 ms / 2,000 ms |
コード長 | 1,148 bytes |
コンパイル時間 | 2,030 ms |
コンパイル使用メモリ | 206,276 KB |
実行使用メモリ | 7,844 KB |
最終ジャッジ日時 | 2025-06-20 01:24:34 |
合計ジャッジ時間 | 4,407 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 51 |
ソースコード
#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 /= 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<long long> 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); } } }