結果

問題 No.1330 Multiply or Divide
ユーザー kotatsugamekotatsugame
提出日時 2021-01-09 02:28:27
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 608 bytes
コンパイル時間 470 ms
コンパイル使用メモリ 67,356 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-28 08:24:28
合計ジャッジ時間 3,265 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 59 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 32 ms
6,944 KB
testcase_07 WA -
testcase_08 AC 77 ms
6,944 KB
testcase_09 AC 78 ms
6,940 KB
testcase_10 AC 79 ms
6,940 KB
testcase_11 AC 75 ms
6,940 KB
testcase_12 AC 76 ms
6,940 KB
testcase_13 AC 1 ms
6,944 KB
testcase_14 AC 1 ms
6,940 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 1 ms
6,944 KB
testcase_17 AC 1 ms
6,944 KB
testcase_18 AC 73 ms
6,940 KB
testcase_19 AC 74 ms
6,940 KB
testcase_20 AC 71 ms
6,944 KB
testcase_21 AC 70 ms
6,944 KB
testcase_22 AC 74 ms
6,944 KB
testcase_23 AC 82 ms
6,944 KB
testcase_24 AC 1 ms
6,940 KB
testcase_25 AC 1 ms
6,940 KB
testcase_26 AC 2 ms
6,944 KB
testcase_27 AC 2 ms
6,940 KB
testcase_28 AC 2 ms
6,944 KB
testcase_29 AC 2 ms
6,940 KB
testcase_30 AC 2 ms
6,944 KB
testcase_31 AC 1 ms
6,944 KB
testcase_32 AC 2 ms
6,944 KB
testcase_33 AC 1 ms
6,944 KB
testcase_34 AC 55 ms
6,944 KB
testcase_35 AC 16 ms
6,944 KB
testcase_36 AC 48 ms
6,944 KB
testcase_37 AC 43 ms
6,940 KB
testcase_38 AC 28 ms
6,940 KB
testcase_39 AC 20 ms
6,940 KB
testcase_40 AC 23 ms
6,940 KB
testcase_41 AC 13 ms
6,944 KB
testcase_42 AC 41 ms
6,944 KB
testcase_43 AC 45 ms
6,940 KB
testcase_44 AC 30 ms
6,940 KB
testcase_45 AC 30 ms
6,940 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<100;j++)
		{
			if(dp[i+j]<dp[i]*B[j])
			{
				dp[i+j]=dp[i]*B[j];
			}
		}
	}
	cout<<(ans==(int)1e9?-1:ans)<<endl;
}
0