結果

問題 No.2039 Copy and Avoid
ユーザー kuronikuroni
提出日時 2022-08-12 22:33:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 29 ms / 2,000 ms
コード長 1,177 bytes
コンパイル時間 1,745 ms
コンパイル使用メモリ 175,400 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 10:50:16
合計ジャッジ時間 2,937 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 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 3 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 28 ms
4,348 KB
testcase_14 AC 28 ms
4,348 KB
testcase_15 AC 28 ms
4,348 KB
testcase_16 AC 26 ms
4,348 KB
testcase_17 AC 3 ms
4,348 KB
testcase_18 AC 3 ms
4,348 KB
testcase_19 AC 3 ms
4,348 KB
testcase_20 AC 4 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 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 <bits/stdc++.h>
using namespace std;

const long long INF = 1E18 + 7;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, m, a, b; cin >> n >> m >> a >> b;
    vector<int> c(m);
    for (int i = 0; i < m; i++) {
        cin >> c[i];
    }
    vector<int> div;
    for (int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            div.push_back(i);
            if (n / i != i) {
                div.push_back(n / i);
            }
        }
    }
    sort(div.begin(), div.end());
    int d = div.size();
    vector<long long> dst(d, INF);
    long long ans = INF;
    dst[0] = 0;
    for (int i = 0; i < d; i++) {
        int max_div = n + 1;
        for (int v : c) {
            if (v % div[i] == 0) {
                max_div = min(max_div, v);
            }
        }
        if (max_div > n) {
            ans = min(ans, dst[i] + 1LL * (n / div[i] - 1) * a);
        }
        for (int j = i + 1; j < d; j++) {
            if (div[j] < max_div && div[j] % div[i] == 0) {
                dst[j] = min(dst[j], dst[i] + b + 1LL * (div[j] / div[i] - 1) * a);
            }
        }
    }
    cout << (ans == INF ? -1 : ans);
}
0