結果
| 問題 |
No.2039 Copy and Avoid
|
| コンテスト | |
| ユーザー |
たたき@競プロ
|
| 提出日時 | 2023-07-17 02:39:47 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,144 bytes |
| コンパイル時間 | 5,675 ms |
| コンパイル使用メモリ | 317,992 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-09-17 21:19:47 |
| 合計ジャッジ時間 | 7,205 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 11 WA * 20 |
ソースコード
#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>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];
}
たたき@競プロ