結果

問題 No.1330 Multiply or Divide
コンテスト
ユーザー fura
提出日時 2021-01-09 19:03:37
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 789 ms / 2,000 ms
コード長 637 bytes
コンパイル時間 1,897 ms
コンパイル使用メモリ 197,984 KB
実行使用メモリ 8,064 KB
最終ジャッジ日時 2025-06-20 01:25:28
合計ジャッジ時間 17,277 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 51
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:9:26: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    9 |         lint n,m,p; scanf("%lld%lld%lld",&n,&m,&p);
      |                     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
main.cpp:11:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   11 |         rep(i,n) scanf("%lld",&a[i]);
      |                  ~~~~~^~~~~~~~~~~~~~

ソースコード

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]);

	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