結果

問題 No.1330 Multiply or Divide
ユーザー kotatsugamekotatsugame
提出日時 2021-01-09 02:28:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 94 ms / 2,000 ms
コード長 609 bytes
コンパイル時間 463 ms
コンパイル使用メモリ 67,072 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-28 08:24:36
合計ジャッジ時間 3,359 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 62 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 33 ms
5,376 KB
testcase_07 AC 94 ms
5,376 KB
testcase_08 AC 82 ms
5,376 KB
testcase_09 AC 83 ms
5,376 KB
testcase_10 AC 78 ms
5,376 KB
testcase_11 AC 80 ms
5,376 KB
testcase_12 AC 81 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 80 ms
5,376 KB
testcase_19 AC 74 ms
5,376 KB
testcase_20 AC 74 ms
5,376 KB
testcase_21 AC 73 ms
5,376 KB
testcase_22 AC 74 ms
5,376 KB
testcase_23 AC 81 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 1 ms
5,376 KB
testcase_26 AC 1 ms
5,376 KB
testcase_27 AC 1 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 1 ms
5,376 KB
testcase_30 AC 2 ms
5,376 KB
testcase_31 AC 2 ms
5,376 KB
testcase_32 AC 1 ms
5,376 KB
testcase_33 AC 1 ms
5,376 KB
testcase_34 AC 56 ms
5,376 KB
testcase_35 AC 17 ms
5,376 KB
testcase_36 AC 49 ms
5,376 KB
testcase_37 AC 44 ms
5,376 KB
testcase_38 AC 28 ms
5,376 KB
testcase_39 AC 20 ms
5,376 KB
testcase_40 AC 24 ms
5,376 KB
testcase_41 AC 14 ms
5,376 KB
testcase_42 AC 43 ms
5,376 KB
testcase_43 AC 49 ms
5,376 KB
testcase_44 AC 31 ms
5,376 KB
testcase_45 AC 31 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:8:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    8 | main()
      | ^~~~

ソースコード

diff #

#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<1000;j++)
		{
			if(dp[i+j]<dp[i]*B[j])
			{
				dp[i+j]=dp[i]*B[j];
			}
		}
	}
	cout<<(ans==(int)1e9?-1:ans)<<endl;
}
0