結果
| 問題 |
No.1330 Multiply or Divide
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-01-08 21:52:33 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,903 bytes |
| コンパイル時間 | 1,406 ms |
| コンパイル使用メモリ | 102,608 KB |
| 最終ジャッジ日時 | 2025-01-17 11:50:20 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 2 WA * 44 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:33:29: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
33 | for (auto &&i : a) scanf("%d", &i);
| ~~~~~^~~~~~~~~~
ソースコード
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>
static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;
template<class T> constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;
template <class T, class U>
vector<T> make_v(U size, const T& init){ return vector<T>(static_cast<size_t>(size), init); }
template<class... Ts, class U>
auto make_v(U size, Ts... rest) { return vector<decltype(make_v(rest...))>(static_cast<size_t>(size), make_v(rest...)); }
template<class T> void chmin(T &a, const T &b){ a = (a < b ? a : b); }
template<class T> void chmax(T &a, const T &b){ a = (a > b ? a : b); }
int main() {
int n, m, p;
cin >> n >> m >> p;
vector<int> a(n);
vector<int> b(n);
for (auto &&i : a) scanf("%d", &i);
int X = 0;
for (int i = 0; i < n; ++i) {
while(a[i]%p == 0) {
a[i] /= p;
b[i]++;
}
X = max(X, b[i]);
}
auto x = *max_element(a.begin(),a.end());
if(x == 1) {
puts("-1");
return 0;
}
vector<int> mx(X+1, 0);
for (int i = 0; i < n; ++i) {
chmax(mx[b[i]], a[i]);
}
vector<int> mae(X+1, 0);
for (int i = 0; i <= X; ++i) {
if(mx[i] == 0) continue;
mae[i] = mx[i];
for (int j = 0; j < X; ++j) {
mae[i] *= p;
}
}
vector<ll> dp(10000, 1);
int ans = INF<int>;
for (int i = 0; i < 10000; ++i) {
if(dp[i] >= m){
ans = min(ans, i);
cout << ans << "\n";
return 0;
}
for (int j = 0; j <= X; ++j) {
if(dp[i]*mae[j] >= m) chmin(ans, i+1);
chmax(dp[i+j+1], dp[i]*mx[j]);
}
cout << i << "\n";
}
return 0;
}