結果
| 問題 |
No.375 立方体のN等分 (1)
|
| コンテスト | |
| ユーザー |
はむ吉🐹
|
| 提出日時 | 2016-06-04 23:56:03 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,395 bytes |
| コンパイル時間 | 938 ms |
| コンパイル使用メモリ | 79,888 KB |
| 実行使用メモリ | 10,272 KB |
| 最終ジャッジ日時 | 2024-10-08 10:48:14 |
| 合計ジャッジ時間 | 12,587 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 4 TLE * 2 -- * 26 |
コンパイルメッセージ
main.cpp: In function 'T compute_min(T) [with T = long long int]':
main.cpp:63:1: warning: control reaches end of non-void function [-Wreturn-type]
63 | }
| ^
ソースコード
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <vector>
template <typename T> std::vector<T> factorize(T n) {
std::vector<T> fs;
for (auto i = 2; i * i < n; i++)
{
while (n % i == 0)
{
fs.push_back(i);
n /= i;
}
}
if (n > 1)
{
fs.push_back(n);
}
return fs;
}
template <typename T> T compute_max(T n) {
return n - 1;
}
template <typename T> T compute_min(T n) {
auto fs = factorize(n);
if (fs.size() == 1)
{
return fs[0] - 1;
}
else if (fs.size() == 2)
{
return fs[0] + fs[1] - 2;
}
else if (fs.size() == 3)
{
return fs[0] + fs[1] + fs[2] - 3;
}
else
{
T lim = std::ceil(3.0 * std::cbrt((double)n));
for (auto s = lim; s < n - 1; s++)
{
for (auto x = 1; x < s; x++)
{
for (auto y = x; y < s - x; y++)
{
auto z = s - x - y;
if (x * y * z == n)
{
return s - 3;
}
}
}
}
}
}
int main() {
long long n;
std::cin >> n;
auto tmin = compute_min(n);
auto tmax = compute_max(n);
std::cout << tmin << " " << tmax << std::endl;
return EXIT_SUCCESS;
}
はむ吉🐹