結果

問題 No.2039 Copy and Avoid
ユーザー pockynypockyny
提出日時 2022-08-13 20:05:51
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 105 ms / 2,000 ms
コード長 1,381 bytes
コンパイル時間 1,349 ms
コンパイル使用メモリ 104,316 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-25 04:46:55
合計ジャッジ時間 3,553 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 4 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 5 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 2 ms
4,348 KB
testcase_12 AC 2 ms
4,348 KB
testcase_13 AC 100 ms
4,348 KB
testcase_14 AC 105 ms
4,348 KB
testcase_15 AC 98 ms
4,348 KB
testcase_16 AC 90 ms
4,348 KB
testcase_17 AC 4 ms
4,348 KB
testcase_18 AC 4 ms
4,348 KB
testcase_19 AC 5 ms
4,348 KB
testcase_20 AC 6 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
testcase_23 AC 2 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 3 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 <map>
#include <set>
#include <algorithm>
#include <vector>

using namespace std;
typedef long long ll;
ll c[5010];
int main(){
    ll i,n,m,a,b; cin >> n >> m >> a >> b;
    for(i=0;i<m;i++) cin >> c[i];
    sort(c,c + m);
    map<ll,ll> mp;
    set<ll> s;
    mp[1] = 0; s.insert(1);
    while(s.size()){
        ll x = *s.begin(); s.erase(x);
        ll nn = n/x;
        ll val = mp[x];
        vector<ll> d1,d2;
        for(i=1;i*i<=nn;i++){
            if(nn%i==0){
                if(i!=1) d1.push_back(i);
                if(i*i!=nn) d2.push_back(nn/i);
            }
        }
        reverse(d2.begin(),d2.end());
        d1.insert(d1.end(),d2.begin(),d2.end());
        int j = 0;
        for(i=0;i<d1.size();i++){
            int now = d1[i]*x;
            bool f = false;
            while(j<m && c[j]<=now){
                if(c[j]>=x && c[j]%x==0) f = true;
                j++;
            }
            if(f) break;
            s.insert(now);
            //if(now==6) cout << d1[i] << " vvv " << val << " " << x << endl;
            if(mp.find(now)==mp.end()) mp[now] = val + (ll)(d1[i] - 1)*a + b;
            else mp[now] = min(mp[now],val + (ll)(d1[i] - 1)*a + b);
        }
    }
    if(mp.find(n)==mp.end()) cout << -1 << "\n";
    else cout << mp[n] - b << "\n";
    //for(auto x:mp) cout << x.first << " " << x.second << "\n";
}
0