結果

問題 No.1862 Copy and Paste
ユーザー vjudge1
提出日時 2024-11-26 14:50:42
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,214 bytes
コンパイル時間 3,319 ms
コンパイル使用メモリ 160,968 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-11-26 14:50:47
合計ジャッジ時間 2,765 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 4
other AC * 1 WA * 26
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:59:41: warning: ‘res’ may be used uninitialized in this function [-Wmaybe-uninitialized]
   59 |                 ans = min(ans, i*x + res*y);
      |                                      ~~~^~

ソースコード

diff #

#include<bits/stdc++.h>
#define ll __int128
#define il inline
#define ls p<<1
#define rs p<<1|1
const ll N = 1e5 + 10;
const ll mod = 1e9+7;
const ll inf = 2e18;

using namespace std;

void read(ll &x) {
	x = 0;
	char c = getchar();
	ll f = 0;
	for (;!isdigit(c); c = getchar())
		f |= c == '-';
	for (; isdigit(c); c = getchar())
		x = x*10 + (c ^ '0');
	if (f) x = -x;
}

ll n, x, y, ans = inf;

il bool solve(ll f, ll z) {
	ll a = z / f, b = z % f;
	ll numd = b, numz = f-b;
	ll res = 1; 
	for (ll i = 1; i <= numd; i++) {
		res *= (a+2);
		if (res > n) return 1;
	}
	for (ll i = 1; i <= numz; i++) {
		res *= (a+1);
		if (res > n) return 1;
	}
	return 0;
}


int main() {
//	freopen("dice.in","r",stdin);
//	freopen("dice.out","w",stdout);
	read(n); read(x); read(y);
	ll len = log2((long long)n)+2;
	// O(logn * logn * logn)
	for (ll i = 1; i <= len; i++) { // ??????
		ll l = i, r = n+1, res; 
		while (l <= r) { // ??????
			ll mid = (l + r) >> 1;
			if (solve(i, mid)) {
				r = mid-1;
				res = mid; 
			} else {
				l = mid+1;
			}
		}
		//cout << i << " " << res << endl;
		ans = min(ans, i*x + res*y);
	}
	cout << (unsigned long long)ans << "\n";	
	return 0;
}
/*
1000000000000000000 2312241 2424211
*/
0