結果

問題 No.375 立方体のN等分 (1)
ユーザー はむ吉🐹はむ吉🐹
提出日時 2016-06-04 23:56:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,395 bytes
コンパイル時間 996 ms
コンパイル使用メモリ 80,184 KB
実行使用メモリ 8,704 KB
最終ジャッジ日時 2024-04-17 01:54:34
合計ジャッジ時間 11,713 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 4,509 ms
6,944 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 TLE -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 | }
      | ^

ソースコード

diff #

#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;
}
0