結果

問題 No.1330 Multiply or Divide
ユーザー furafura
提出日時 2021-01-08 22:53:20
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 723 bytes
コンパイル時間 1,997 ms
コンパイル使用メモリ 201,972 KB
実行使用メモリ 8,052 KB
最終ジャッジ日時 2023-08-10 11:04:24
合計ジャッジ時間 10,222 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 798 ms
7,772 KB
testcase_02 WA -
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 409 ms
7,776 KB
testcase_07 AC 424 ms
7,772 KB
testcase_08 AC 694 ms
7,780 KB
testcase_09 AC 622 ms
7,844 KB
testcase_10 AC 691 ms
7,816 KB
testcase_11 AC 737 ms
7,788 KB
testcase_12 AC 701 ms
7,776 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 28 ms
4,680 KB
testcase_19 AC 28 ms
4,672 KB
testcase_20 AC 28 ms
4,644 KB
testcase_21 AC 28 ms
4,588 KB
testcase_22 AC 27 ms
4,676 KB
testcase_23 WA -
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 WA -
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 2 ms
4,384 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 22 ms
4,380 KB
testcase_35 AC 7 ms
4,380 KB
testcase_36 AC 19 ms
4,380 KB
testcase_37 AC 17 ms
4,380 KB
testcase_38 AC 11 ms
4,380 KB
testcase_39 AC 8 ms
4,380 KB
testcase_40 AC 10 ms
4,380 KB
testcase_41 AC 5 ms
4,380 KB
testcase_42 AC 16 ms
4,380 KB
testcase_43 AC 18 ms
4,384 KB
testcase_44 AC 410 ms
8,052 KB
testcase_45 AC 409 ms
7,844 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;
using lint=long long;

int main(){
	lint n,m,p; scanf("%lld%lld%lld",&n,&m,&p);
	vector<lint> a(n);
	rep(i,n) scanf("%lld",&a[i]);

	if(m==1){
		puts("0");
		return 0;
	}

	lint mx=*max_element(a.begin(),a.end());
	if(mx>=m){
		puts("1");
		return 0;
	}

	vector<lint> b(n),e(n); // a[i] = b[i] * p^e[i]
	rep(i,n){
		for(b[i]=a[i];b[i]%p==0;b[i]/=p) e[i]++;
	}

	vector<lint> dp(1000,-1);
	dp[0]=1;
	rep(i,n){
		rep(w,1001-(e[i]+1)) if(dp[w]!=-1) {
			dp[w+e[i]+1]=min(max(dp[w+e[i]+1],dp[w]*b[i]),m);
		}
	}

	lint tar=(m+mx-1)/mx;
	rep(w,1001){
		if(dp[w]>=tar){
			printf("%d\n",w+1);
			return 0;
		}
	}
	puts("-1");

	return 0;
}
0