結果
問題 |
No.1330 Multiply or Divide
|
ユーザー |
|
提出日時 | 2024-04-02 02:52:59 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,201 bytes |
コンパイル時間 | 2,209 ms |
コンパイル使用メモリ | 196,636 KB |
最終ジャッジ日時 | 2025-02-20 19:32:53 |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 39 WA * 7 |
ソースコード
#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 = 35; 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) { continue; } ll x = A[i]; ll y = ep * x; vector<ll> ndp(K + 1, 1); for (int j = 0;j <= K;j++) { //iをつかわない or dp[j] = over; if (dp[j] == M + 1) { ndp[j] = M + 1; continue; } else { ndp[j] = max(ndp[j], dp[j]); } //iをつかう if (dp[j] * y > M) { if (j != K) ndp[j + 1] = max(ndp[j], M + 1); } else { if (j + i + 1 <= K) ndp[j+i+1] = max(ndp[j+i+1], dp[j] * x); } } swap(dp, ndp); ep *= P; } for (int i = 1;i <= K;i++) { if (dp[i] == M + 1) { cout << i << endl; return 0; } } cout << -1 << endl; }