結果

問題 No.2039 Copy and Avoid
ユーザー kotatsugamekotatsugame
提出日時 2022-08-12 22:06:42
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 35 ms / 2,000 ms
コード長 809 bytes
コンパイル時間 822 ms
コンパイル使用メモリ 79,616 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 10:12:00
合計ジャッジ時間 2,203 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 3 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 4 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,348 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 34 ms
4,348 KB
testcase_14 AC 34 ms
4,348 KB
testcase_15 AC 35 ms
4,348 KB
testcase_16 AC 32 ms
4,348 KB
testcase_17 AC 4 ms
4,348 KB
testcase_18 AC 4 ms
4,348 KB
testcase_19 AC 4 ms
4,348 KB
testcase_20 AC 5 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 1 ms
4,348 KB
testcase_24 AC 2 ms
4,348 KB
testcase_25 AC 2 ms
4,348 KB
testcase_26 AC 2 ms
4,348 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 2 ms
4,348 KB
testcase_29 AC 2 ms
4,348 KB
testcase_30 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int N,M,A,B;
int C[5000];
int main()
{
	cin>>N>>M>>A>>B;
	for(int i=0;i<M;i++)cin>>C[i];
	sort(C,C+M);
	vector<int>dv;
	for(int i=1;i*i<=N;i++)if(N%i==0)
	{
		dv.push_back(i);
		if(i<N/i)dv.push_back(N/i);
	}
	sort(dv.begin(),dv.end());
	vector<long long>dp(dv.size(),(long long)1e18);
	dp[0]=0;
	vector<int>tmp;
	for(int i=0;i<dv.size();i++)
	{
		tmp.clear();
		for(int j=0;j<M;j++)if(C[j]%dv[i]==0)tmp.push_back(C[j]);
		for(int j=i+1;j<dv.size();j++)if(dv[j]%dv[i]==0)
		{
			if(lower_bound(tmp.begin(),tmp.end(),dv[i])==upper_bound(tmp.begin(),tmp.end(),dv[j]))
			{
				dp[j]=min(dp[j],dp[i]+B+dv[j]/dv[i]*(long long)A-A);
			}
		}
	}
	if(dp[dv.size()-1]==(long long)1e18)cout<<-1<<endl;
	else cout<<dp[dv.size()-1]-B<<endl;
}
0