結果

問題 No.1862 Copy and Paste
コンテスト
ユーザー vjudge1
提出日時 2026-06-26 13:01:48
言語 C++23
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,709 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,026 ms
コンパイル使用メモリ 334,240 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-06-26 13:01:57
合計ジャッジ時間 3,405 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
#include <cassert>
#pragma GCC optimize("O3", "Ofast")
#define int long long
#define ll long long
#define se second
#define fi first
#define pb push_back
#define lf (id<<1)
#define rg ((id<<1)|1)
#define md ((l+r)>>1)
using namespace std;
typedef pair<int,int> pii;
typedef pair<pii,pii> ipii;
const int MAXN = 3e5+10;
const int MAXA = 5e4+10;
const int SQRT = 300;
const ll INF = 2e9;
const int MOD = 1e9+7;
const int LOG = 20;
ll sum(auto a, auto b){ 
	ll te = a+MOD+b; 
	for(; te >= MOD; ) te -= MOD;
	return te;
}
void chsum(int &a, auto b){ a = sum(a,b); }
ll mul(auto a, auto b){ return 1ll*a*b%MOD; }
void chmul(auto &a, auto b){ a = mul(a,b); }
void chmn(auto &a, auto b){ a = min(a, b); }
void chmx(auto &a, auto b){ a = max(a, b); }

int expo(int a, int b){
	if(b==0) return 1;
	int te = expo(a, b/2); te = mul(te,te); // temporary -> te
	return (b%2 ? mul(te, a) : te);
}
vector <int> dx = {0, 0, -1, 1};
vector<int> dy = {-1, 1, 0, 0};

int a, b, x;

signed main(){ 
	// ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>a>>b>>x;
	if(x==1){
		cout << "0\n"; exit(0);
	}

	int ans = a+(x-1)*b; // buat kali x
	for(int i=2; i<=30; i++){
		int l=2, r=x, mid=0, cnt=-1;
		while(l <= r){
			mid = md;
			int tot = 1;
			for(int j=1; j<=i; j++){
				tot = min(INF, tot*mid);
			}
			if(tot >= x) cnt = mid, r = mid-1;
			else l = mid+1;
		}
		// kali cnt-1 sebanyak i kali
		int tot = 1;
		int cost = i*(a+(cnt-2)*b);
		for(int j=1; j<=i; j++) tot *= (cnt-1);

		for(int j=1; j<=i; j++){
			if(tot < x){
				cost += b;
				tot = tot/(cnt-1)*cnt;
			}
		}
		// cout << i << ' '<< cnt << ' '<< tot << ' '<< cost << " cst\n";
		chmn(ans, cost);
	}
	cout << ans << '\n';
} 
0