結果
| 問題 |
No.1330 Multiply or Divide
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-01-09 02:28:27 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 608 bytes |
| コンパイル時間 | 732 ms |
| コンパイル使用メモリ | 66,816 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-16 22:08:37 |
| 合計ジャッジ時間 | 3,581 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 45 WA * 1 |
コンパイルメッセージ
main.cpp:8:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
8 | main()
| ^~~~
ソースコード
#include<iostream>
#include<algorithm>
using namespace std;
int N,M,P;
int A[2<<17];
long dp[1000];
int B[32];
main()
{
cin>>N>>M>>P;
int mM=M;
for(int i=0;i<N;i++)
{
cin>>A[i];
mM=min(mM,M/A[i]);
}
if(mM==0)
{
cout<<1<<endl;
return 0;
}
dp[0]=1;
for(int i=0;i<N;i++)
{
int a=A[i],c=1;
while(a%P==0)a/=P,c++;
B[c]=max(B[c],a);
}
int ans=1e9;
for(int i=0;i<1000;i++)if(dp[i]>0)
{
if(dp[i]>mM)
{
ans=min(ans,i+1);
continue;
}
for(int j=1;j<32&&i+j<100;j++)
{
if(dp[i+j]<dp[i]*B[j])
{
dp[i+j]=dp[i]*B[j];
}
}
}
cout<<(ans==(int)1e9?-1:ans)<<endl;
}