結果

問題 No.1862 Copy and Paste
ユーザー milanis48663220milanis48663220
提出日時 2022-03-04 23:19:27
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 2,564 bytes
コンパイル時間 1,131 ms
コンパイル使用メモリ 121,036 KB
実行使用メモリ 4,356 KB
最終ジャッジ日時 2023-10-11 10:48:23
合計ジャッジ時間 2,405 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;

template<typename T>
vector<vector<T>> vec2d(int n, int m, T v){
    return vector<vector<T>>(n, vector<T>(m, v));
}

template<typename T>
vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){
    return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v)));
}

template<typename T>
void print_vector(vector<T> v, char delimiter=' '){
    if(v.empty()) {
        cout << endl;
        return;
    }
    for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter;
    cout << v.back() << endl;
}

using P = pair<int, int>;

vector<int> facs(int a){
    vector<int> ans;
    for(int x = 1; x*x <= a; x++){
        if(a%x == 0){
            ans.push_back(x);
        }
        if(x*x != a) ans.push_back(x);
    }
    sort(ans.begin(), ans.end());
    return ans;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    ll a, b, n; cin >> a >> b >> n;
    if(n == 1){
        cout << 0 << endl;
        return 0;
    }
    auto f = [&](ll x){
        return a+b*(x-1);
    };
    auto judge = [&](ll a, int r){
        ll x = 1;
        for(int i = 0; i < r; i++){
            x *= a;
            if(x >= n) return true;
        }
        return false;
    };
    ll ans = 4e18;
    for(int i = 1; i <= 30; i++){
        ll l = 0, r = n+1;
        while(r-l > 1){
            ll a = (l+r)/2;
            if(judge(a, i)) r = a;
            else l = a;
        }
        ll tmp = 1;
        ll score = 0;
        for(int j = 0; j < i; j++){
            int rem = i-j;
            bool ok = false;
            ll tt = tmp;
            for(int k = 0; k < rem; k++){
                tt *= r-1;
                if(tt >= n) ok = true; 
            }
            int x = r;
            if(ok) x--;
            tmp *= x;
            score += f(x);
        }
        assert(tmp >= n);
        chmin(ans, score);
    }
    cout << ans << endl;
}
0