結果

問題 No.1330 Multiply or Divide
ユーザー furafura
提出日時 2021-01-08 23:39:47
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 677 bytes
コンパイル時間 2,090 ms
コンパイル使用メモリ 202,868 KB
実行使用メモリ 8,192 KB
最終ジャッジ日時 2024-04-28 06:26:00
合計ジャッジ時間 18,110 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 810 ms
8,064 KB
testcase_02 WA -
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 416 ms
7,936 KB
testcase_07 AC 394 ms
8,064 KB
testcase_08 AC 700 ms
8,192 KB
testcase_09 AC 640 ms
8,064 KB
testcase_10 AC 700 ms
8,064 KB
testcase_11 AC 745 ms
8,192 KB
testcase_12 AC 702 ms
8,064 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 812 ms
8,064 KB
testcase_19 AC 810 ms
8,064 KB
testcase_20 AC 815 ms
8,064 KB
testcase_21 AC 811 ms
8,192 KB
testcase_22 AC 810 ms
8,064 KB
testcase_23 AC 814 ms
8,192 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 2 ms
5,376 KB
testcase_31 AC 2 ms
5,376 KB
testcase_32 AC 2 ms
5,376 KB
testcase_33 AC 2 ms
5,376 KB
testcase_34 AC 607 ms
6,784 KB
testcase_35 AC 166 ms
5,376 KB
testcase_36 AC 537 ms
6,400 KB
testcase_37 AC 476 ms
6,144 KB
testcase_38 AC 299 ms
5,376 KB
testcase_39 AC 207 ms
5,376 KB
testcase_40 AC 247 ms
5,376 KB
testcase_41 AC 127 ms
5,376 KB
testcase_42 AC 443 ms
5,888 KB
testcase_43 AC 513 ms
6,400 KB
testcase_44 AC 415 ms
8,064 KB
testcase_45 AC 416 ms
8,064 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;
	}

	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,1000-(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 mx=*max_element(a.begin(),a.end());
	lint tar=m/mx+1;
	rep(w,1000){
		if(dp[w]>=tar){
			printf("%d\n",w+1);
			return 0;
		}
	}
	puts("-1");

	return 0;
}
0