結果
| 問題 |
No.1330 Multiply or Divide
|
| コンテスト | |
| ユーザー |
Example0911
|
| 提出日時 | 2021-01-09 10:01:32 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 128 ms / 2,000 ms |
| コード長 | 853 bytes |
| コンパイル時間 | 1,938 ms |
| コンパイル使用メモリ | 198,060 KB |
| 実行使用メモリ | 7,848 KB |
| 最終ジャッジ日時 | 2025-06-20 01:23:38 |
| 合計ジャッジ時間 | 4,952 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 51 |
ソースコード
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll INF = (1LL << 61);
ll mod = (ll)1e9 + 7;
// i回操作をするときのxの値の最大値
ll dp[100010];
signed main() {
ll N, M, P; cin >> N >> M >> P;
vector<ll>A(N); for (int i = 0; i < N; i++)cin >> A[i];
// 最後に掛けることができる
ll t = 0;
for (int i = 0; i < N; i++)t = max(t, A[i]);
// 割る操作をi回するときの最大値
vector<ll>m(62, 1);
for (int i = 0; i < N; i++) {
ll cnt = 0;
while (A[i] % P == 0) {
A[i] /= P;
cnt++;
}
m[cnt] = max(m[cnt], A[i]);
}
dp[0] = 1;
for (int i = 0; i < 10010; i++) {
if (dp[i] * t > M) {
cout << i + 1 << endl; return 0;
}
for (int j = 0; j <= 60; j++) {
// 遷移
dp[i + j + 1] = max(dp[i + j + 1], dp[i] * m[j]);
}
}
cout << -1 << endl;
}
Example0911