結果

問題 No.2039 Copy and Avoid
ユーザー tassei903tassei903
提出日時 2022-08-19 18:50:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,224 bytes
コンパイル時間 2,521 ms
コンパイル使用メモリ 210,588 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-16 22:11:42
合計ジャッジ時間 12,627 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,572 ms
5,248 KB
testcase_01 WA -
testcase_02 AC 4 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 8 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 1,558 ms
5,376 KB
testcase_14 AC 1,573 ms
5,376 KB
testcase_15 AC 1,509 ms
5,376 KB
testcase_16 AC 1,252 ms
5,376 KB
testcase_17 AC 5 ms
5,376 KB
testcase_18 AC 5 ms
5,376 KB
testcase_19 AC 5 ms
5,376 KB
testcase_20 AC 14 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 1 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 WA -
testcase_28 AC 2 ms
5,376 KB
testcase_29 WA -
testcase_30 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define FOR(i, n, m) for (int i = n; i < m; i++)
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void print() { std::cout << std::endl; }
template<class T, class... A> void print(const T& first, const A&... rest) { std::cout << first << " "; print(rest...); }
template<class... A> void print(const A&... rest) { print(rest...); }
# define SZ(x) ((int)(x).size())
const ll INF = 1LL<<60;

int main() {
    int n, m;
    ll a, b;
    cin >> n >> m >> a >> b;
    set<int> c;
    rep(i,m) {
        int x;
        cin >> x;
        c.insert(x);
    }
    vector<int> div;
    for (int x = 1; x * x <= n; x++) {
        if (x * x == n)div.emplace_back(x);
        else if (n % x == 0){
            div.emplace_back(x);
            div.emplace_back(n/x);
        }
    }
    sort(div.begin(), div.end());
    reverse(div.begin(), div.end());
    //cout << "ok" << endl;
    auto check = [&](int x, int y) -> bool {
        x -= y;
        if (x / y < m) {
            while (x >= y) {
                if (c.find(x) != c.end())return false;
                x -= y;
            }
            return true;
        }
        else {
            for(auto z:c) {
                if (z >= x)break;
                if (z % y == 0 && z < x)return false;
            }
            return true;
        }
        
    };

    map<int, ll> memo;
    auto saiki = [&](auto&& saiki, int x) -> ll{
        if (x == 1)return 0;
        if (memo.find(x)!=memo.end())return memo[x];
        ll ans = INF;
        for(int y : div) {
            //print("x,y", x, y);
            if (y < x && x % y == 0 && check(x, y)) {
                ll d = x / y;
                d--;
                chmin(ans, saiki(saiki, y) + b + d * a);
            }
        }
        //cout << x << " " << ans << endl;
        memo[x] = ans;
        return ans;
    };
    if (n == 1)return 0;
    else {
        auto z = saiki(saiki, n);
        if (z == INF)cout << -1 << endl;
        else cout << z - b << endl;
    }

    
}
0