結果
| 問題 | No.1330 Multiply or Divide |
| コンテスト | |
| ユーザー |
nok0
|
| 提出日時 | 2020-10-30 16:37:46 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.90.0) |
| 結果 |
AC
|
| 実行時間 | 29 ms / 2,000 ms |
| + 317µs | |
| コード長 | 764 bytes |
| 記録 | |
| コンパイル時間 | 1,046 ms |
| コンパイル使用メモリ | 216,644 KB |
| 実行使用メモリ | 9,412 KB |
| 最終ジャッジ日時 | 2026-07-12 08:31:37 |
| 合計ジャッジ時間 | 3,995 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 51 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define REP(i, x) for(int i = 0; i < (x); i++)
template <class T>
inline bool chmax(T &a, T b) {
if(a < b) {
a = b;
return true;
}
return false;
}
int main() {
int n, m, p;
scanf("%d %d %d", &n, &m, &p);
vector a(n, 0), b(50, 0);
REP(i, n) { scanf("%d", &a[i]); }
int maxa = *max_element(a.begin(), a.end());
REP(i, n) {
int cnt = 1;
while(a[i] % p == 0) a[i] /= p, cnt++;
chmax(b[cnt], a[i]);
}
vector achive(3100, 1ll);
REP(i, 3000) {
REP(j, 50) {
if(achive[i] <= m) chmax(achive[i + j], achive[i] * b[j]);
}
}
REP(i, 3100) {
if(achive[i] * maxa > m) {
printf("%d\n", i + 1);
return 0;
}
}
puts("-1");
return 0;
}
nok0