結果

問題 No.1862 Copy and Paste
ユーザー vjudge1
提出日時 2024-05-01 23:43:08
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,191 ms / 2,000 ms
コード長 559 bytes
コンパイル時間 4,164 ms
コンパイル使用メモリ 279,120 KB
実行使用メモリ 6,152 KB
最終ジャッジ日時 2024-11-22 07:58:48
合計ジャッジ時間 21,022 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

// Source: https://usaco.guide/general/io

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

ll a, b;
unordered_map<int, ll> mp;

ll solve(int n) {
	if (n == 1) return 0;
	if (mp.find(n) != mp.end()) return mp[n];
	ll ans = (n - 1) * b + a;
	for (auto i = 2; i * i <= n; ++i) {
		auto temp = (n + i - 1) / i;
		auto tmp1 = solve(temp) + b * (i - 1) + a;
		auto tmp2 = solve(i) + b * (temp - 1) + a;
		ans = min({ ans, tmp1, tmp2 });
	}
	return mp[n] = ans;
}

int main(){
	int n; cin >> a >> b >> n;
	cout << solve(n) << endl;

	return 0;
}
0