結果

問題 No.2039 Copy and Avoid
ユーザー publfl2publfl2
提出日時 2022-08-12 22:49:36
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 550 ms / 2,000 ms
コード長 917 bytes
コンパイル時間 772 ms
コンパイル使用メモリ 75,916 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 11:09:56
合計ジャッジ時間 4,812 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 513 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 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 1 ms
4,348 KB
testcase_07 AC 1 ms
4,348 KB
testcase_08 AC 2 ms
4,348 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 1 ms
4,348 KB
testcase_11 AC 1 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 505 ms
4,348 KB
testcase_14 AC 550 ms
4,348 KB
testcase_15 AC 479 ms
4,348 KB
testcase_16 AC 417 ms
4,348 KB
testcase_17 AC 2 ms
4,348 KB
testcase_18 AC 4 ms
4,348 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 9 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 1 ms
4,348 KB
testcase_23 AC 1 ms
4,348 KB
testcase_24 AC 1 ms
4,348 KB
testcase_25 AC 1 ms
4,348 KB
testcase_26 AC 1 ms
4,348 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 2 ms
4,348 KB
testcase_29 AC 1 ms
4,348 KB
testcase_30 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <set>
#include <map>
#include <algorithm>
#include <vector>
#define MAX (long long int)2e18

std::set<int> S;
std::vector<int> V;
std::map<int,long long int> M;
int x[5010];
int main()
{
	int a,b;
	long long int c,d;
	scanf("%d%d%lld%lld",&a,&b,&c,&d);
	for(int i=1;i*i<=a;i++)
	{
		if(a%i==0)
		{
			S.insert(i);
			S.insert(a/i);
		}
	}
	for(int i=1;i<=b;i++)
	{
		int e;
		scanf("%d",&e);
		S.erase(e);
		x[i] = e;
	}
	for(std::set<int> ::iterator it = S.begin();it!=S.end();it++) V.push_back(*it);
	
	M[0] = 0;
	for(int i=1;i<V.size();i++)
	{
		int s = V[i];
		M[s] = MAX;
		for(int j=0;j<i;j++)
		{
			int t = V[j];
			if(s%t==0)
			{
				long long int val;
				for(int k=1;k<=b;k++)
				{
					if(t<=x[k]&&x[k]<=s&&x[k]%t==0) goto u;
				}
				val = M[t] + (s/t - 1)*c + d;
				M[s] = M[s]<val?M[s]:val;
				u:;
			}
		}
	}
	if(M[a]==MAX) printf("-1");
	else printf("%lld",M[a]-d);
}
0