結果

問題 No.1330 Multiply or Divide
ユーザー 👑 Nachia
提出日時 2021-01-09 13:53:09
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 88 ms / 2,000 ms
コード長 646 bytes
コンパイル時間 1,787 ms
コンパイル使用メモリ 194,872 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2025-06-20 01:24:42
合計ジャッジ時間 4,430 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 51
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:13:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   13 |         scanf("%llu%llu%llu",&N,&M,&P);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:17:29: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   17 |                 ULL a; scanf("%llu",&a);
      |                        ~~~~~^~~~~~~~~~~

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using LL=long long;
using ULL=unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)

ULL N,M,P;
ULL maxA;
ULL D[70];
ULL dp[5000];

int main(){
	scanf("%llu%llu%llu",&N,&M,&P);
	rep(i,70) D[i]=1;
	maxA=1;
	rep(i,N){
		ULL a; scanf("%llu",&a);
		int d=1;
		ULL b=a; while(b%P==0){ b/=P; d++; }
		D[d]=max(D[d],b);
		maxA=max(maxA,a);
	}
	rep(i,5000) dp[i]=1;
	M=M/maxA;
	int ans=-1;
	rep(i,5000){
		if(dp[i]>M){ ans=i+1; break; }
		rep(j,70){
			if(D[j]==1) continue;
			if(j==0) continue;
			if(i+j>=5000) continue;
			dp[i+j]=max(dp[i+j],dp[i]*D[j]);
		}
	}
	printf("%d\n",ans);
	return 0;
}
0