結果

問題 No.376 立方体のN等分 (2)
ユーザー wing3196wing3196
提出日時 2016-06-04 23:08:29
言語 C++11
(gcc 11.4.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 814 bytes
コンパイル時間 1,238 ms
コンパイル使用メモリ 147,068 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-07-30 17:50:32
合計ジャッジ時間 9,092 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 WA -
testcase_03 AC 87 ms
4,376 KB
testcase_04 AC 159 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 14 ms
4,376 KB
testcase_09 AC 25 ms
4,380 KB
testcase_10 AC 31 ms
4,380 KB
testcase_11 AC 165 ms
4,376 KB
testcase_12 AC 64 ms
4,376 KB
testcase_13 AC 167 ms
4,376 KB
testcase_14 AC 217 ms
4,376 KB
testcase_15 AC 165 ms
4,376 KB
testcase_16 AC 88 ms
4,376 KB
testcase_17 AC 93 ms
4,376 KB
testcase_18 AC 188 ms
4,376 KB
testcase_19 AC 97 ms
4,380 KB
testcase_20 AC 224 ms
4,380 KB
testcase_21 AC 98 ms
4,376 KB
testcase_22 AC 195 ms
4,376 KB
testcase_23 AC 104 ms
4,376 KB
testcase_24 AC 105 ms
4,380 KB
testcase_25 AC 107 ms
4,376 KB
testcase_26 AC 107 ms
4,376 KB
testcase_27 AC 279 ms
4,376 KB
testcase_28 AC 209 ms
4,376 KB
testcase_29 AC 229 ms
4,380 KB
testcase_30 AC 270 ms
4,376 KB
testcase_31 AC 189 ms
4,376 KB
testcase_32 AC 136 ms
4,380 KB
testcase_33 AC 107 ms
4,380 KB
testcase_34 AC 157 ms
4,376 KB
testcase_35 AC 334 ms
4,380 KB
testcase_36 AC 209 ms
4,380 KB
testcase_37 AC 208 ms
4,376 KB
testcase_38 AC 346 ms
4,380 KB
testcase_39 AC 119 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;

#define int long long

int N;

void GetDiv(vector<int> &res, int n)
{
	int i;
	for (i = 1; i*i < n; i++)
	{
		if (n % i == 0) res.push_back(i);
	}
	if (i*i == n) res.push_back(i);
}

int Solve2D(int n)
{
	int s = sqrt(n) + 1e-1;
	while (n % s) s--;
	return s + n/s;
}

int GetMin(int n)
{
	vector<int> div;
	GetDiv(div, N);
	int l = 0, r = div.size() - 1;
	while (r - l > 10)
	{
		int mid1 = (l*2 + r)/3, mid2 = (l + r*2)/3;
		if (Solve2D(N/div[mid1]) + div[mid1] < Solve2D(N/div[mid2]) + div[mid2]) r = mid2;
		else l = mid1;
	}
	int res = LLONG_MAX;
	for (int i = l; i <= r; i++)
	{
		res = min(res, Solve2D(N/div[i]) + div[i]);
	}
	return res - 3;
}

signed main()
{
	cin >> N;
	printf("%lld %lld\n", GetMin(N), N - 1);
	return 0;
}
0