結果

問題 No.1862 Copy and Paste
ユーザー Bryson Ng
提出日時 2024-05-01 23:41:40
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,164 ms / 2,000 ms
コード長 516 bytes
コンパイル時間 3,552 ms
コンパイル使用メモリ 278,992 KB
実行使用メモリ 6,028 KB
最終ジャッジ日時 2024-11-22 07:57:17
合計ジャッジ時間 20,717 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 27
権限があれば一括ダウンロードができます

ソースコード

diff #

#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