結果

問題 No.2744 Power! or +1
ユーザー Series_205Series_205
提出日時 2024-04-20 17:28:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,935 bytes
コンパイル時間 2,243 ms
コンパイル使用メモリ 197,260 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-20 17:28:28
合計ジャッジ時間 3,342 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 138 ms
6,812 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 6 ms
6,944 KB
testcase_04 AC 11 ms
6,940 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 38 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#define FOR(i, l, r) for(ll i = l; i < r; i++)
#define rep(i, n) FOR(i, 0, n)
#define FORR(i, l, r) for(ll i = r - 1; i >= l; i--)
#define ALL(ar) begin(ar), end(ar)

template <typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {
    return a < b && (a = b, true);
}
template <typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {
    return a > b && (a = b, true);
}
template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) {
    is >> p.first >> p.second;
    return is;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
    os << p.first << ' ' << p.second;
    return os;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
    for(T &x : v) is >> x;
    return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    for(size_t i = 0; i < v.size(); i++) os << (i ? " " : "") << v[i];
    return os;
}
//-------------------------------------------------

void solve() {
    ll n, a, b, c;
    cin >> n >> a >> b >> c;

    vector<ll> dp(n + 1, 1LL << 55);
    dp[1] = 0;

    ll tmp = 1;
    FOR(i, 1, n) {
        tmp *= i;
        if(tmp > n) {
            tmp = gcd(tmp, n);
            chmin(dp[n], dp[i] + c + c);
        }
        chmin(dp[tmp], dp[i] + c);
        chmin(dp[i + 1], dp[i] + a);
        ll cost = b;
        ll nxt = i;
        while(true) {
            chmin(dp[nxt], dp[i] + cost);
            ll now = nxt;
            nxt *= i;
            if(nxt > n) {
                chmin(dp[n], dp[i] + cost * b + c);
                nxt = gcd(nxt, n);
            }
            if(nxt == now) break;
            cost *= b;
            if(cost > dp[n]) break;
        }
    }

    // cout << dp << endl;

    cout << dp.back() << endl;
}

int main() {
    int t = 1;
    // cin >> t;
    while(t--) solve();
}
0