結果

問題 No.1330 Multiply or Divide
ユーザー chocorusk
提出日時 2021-01-09 17:02:03
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 150 ms / 2,000 ms
コード長 1,328 bytes
コンパイル時間 1,456 ms
コンパイル使用メモリ 124,544 KB
最終ジャッジ日時 2025-01-17 15:45:53
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 46
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <stack>
#include <array>
#include <list>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
int main()
{
int n; cin>>n;
ll m, p; cin>>m>>p;
ll a[200020];
for(int i=0; i<n; i++){
cin>>a[i];
}
ll mx=*max_element(a, a+n);
if(mx>m){
cout<<1<<endl;
return 0;
}
ll x[30];
fill(x, x+30, 1);
for(int i=0; i<n; i++){
int c=0;
ll b=a[i];
while(b%p==0){
b/=p;
c++;
}
x[c]=max(x[c], b);
}
ll dp[1024]={};
dp[0]=1;
const ll MAX=1e9+7;
for(int i=0; i<1024; i++){
for(int j=0; i+j+1<1024 && j<30; j++){
dp[i+j+1]=max(dp[i+j+1], min(dp[i]*x[j], MAX));
}
}
for(int i=0; i<1024; i++){
if(dp[i]>m/mx){
cout<<i+1<<endl;
return 0;
}
}
cout<<-1<<endl;
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0