結果

問題 No.2039 Copy and Avoid
ユーザー たたき@競プロたたき@競プロ
提出日時 2023-07-17 02:46:55
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,163 bytes
コンパイル時間 6,850 ms
コンパイル使用メモリ 317,748 KB
実行使用メモリ 5,232 KB
最終ジャッジ日時 2023-10-18 00:16:35
合計ジャッジ時間 7,646 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using mint=modint998244353; //1000000007;
using ll=long long;
using pp=pair<ll,int>;
#define sr string 
#define vc vector
#define db double
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define pque priority_queue
#define bpc(a) __builtin_popcount(a)
int main(){
	int n,m,a,b;cin>>n>>m>>a>>b;
	vc<int>ban(m); rep(i,m)cin>>ban[i];
	vc<int>d;
	for(int i=1;i*i<=n;i++)if(n%i==0){
		d.pb(i);
		if(i!=n/i)d.pb(n/i);
	}
	int k=d.size();
	sort(all(d));
	vc v(k,vc<int>(0));
	rep(i,k){
		int b=n;
		rep(j,m)if(ban[j]%d[i]==0)b=min(b,ban[j]);
		for(int j=i+1;j<k;j++)if(d[j]%d[i]==0){
			if(d[j]>=b)break;
			v[i].pb(j);
		}
	}
	pque<pp,vc<pp>,greater<pp>>q;
	vc<ll>dist(k,1e18);
	dist[0]=0; q.push({0,0});
	while(q.size()){
		auto [di,x]=q.top(); q.pop();
		if(dist[x]<di)continue;
		for(auto au:v[x]){
			ll cost=b+(ll)a*(d[au]/d[x]-1);
			if(dist[au]<=dist[x]+cost)continue;
			dist[au]=dist[x]+cost;
			q.push({dist[au],au});
		}
	}
	if(dist[k-1]==1e18)cout<<-1;
	else cout<<dist[k-1];
}
	
0