結果

問題 No.376 立方体のN等分 (2)
ユーザー mamekinmamekin
提出日時 2016-07-18 15:17:24
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 198 ms / 5,000 ms
コード長 1,807 bytes
コンパイル時間 2,419 ms
コンパイル使用メモリ 107,556 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-06 20:27:01
合計ジャッジ時間 4,110 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 5 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 14 ms
4,380 KB
testcase_11 AC 6 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 AC 9 ms
4,376 KB
testcase_16 AC 177 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 9 ms
4,376 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 3 ms
4,380 KB
testcase_21 AC 187 ms
4,384 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 189 ms
4,376 KB
testcase_24 AC 160 ms
4,376 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 198 ms
4,376 KB
testcase_27 AC 77 ms
4,376 KB
testcase_28 AC 2 ms
4,380 KB
testcase_29 AC 3 ms
4,376 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 23 ms
4,380 KB
testcase_32 AC 78 ms
4,380 KB
testcase_33 AC 108 ms
4,376 KB
testcase_34 AC 55 ms
4,380 KB
testcase_35 AC 55 ms
4,376 KB
testcase_36 AC 109 ms
4,376 KB
testcase_37 AC 109 ms
4,380 KB
testcase_38 AC 30 ms
4,380 KB
testcase_39 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
using namespace std;

void integerFactorization(long long n, vector<long long>& base, vector<int>& expo)
{
    base.clear();
    expo.clear();
    long long a = 2;
    while(a * a <= n){
        int b = 0;
        while(n % a == 0){
            ++ b;
            n /= a;
        }
        if(b > 0){
            base.push_back(a);
            expo.push_back(b);
        }
        ++ a;
    }
    if(n > 1){
        base.push_back(n);
        expo.push_back(1);
    }
}

long long solve(const vector<long long>& base, const vector<int>& expo, int k, const vector<long long>& x)
{
    if(k == base.size()){
        long long ans = 0;
        for(int i=0; i<3; ++i)
            ans += x[i] - 1;
        return ans;
    }

    long long ans = LLONG_MAX;
    vector<long long> y = x;
    for(int a=0; a<=expo[k]; ++a){
        for(int b=0; a+b<=expo[k]; ++b){
            int c = expo[k] - a - b;
            for(int i=0; i<c; ++i)
                y[2] *= base[k];
            ans = min(ans, solve(base, expo, k+1, y));

            y[2] = x[2];
            y[1] *= base[k];
        }
        y[1] = x[1];
        y[0] *= base[k];
    }

    return ans;
}

int main()
{
    long long n;
    cin >> n;

    vector<long long> base;
    vector<int> expo;
    integerFactorization(n, base, expo);

    vector<long long> x(3, 1);
    cout << solve(base, expo, 0, x) << ' ' << (n - 1) << endl;

    return 0;
}
0