結果

問題 No.376 立方体のN等分 (2)
ユーザー odan3240odan3240
提出日時 2016-06-07 16:57:49
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 4,021 ms / 5,000 ms
コード長 1,720 bytes
コンパイル時間 1,019 ms
コンパイル使用メモリ 98,984 KB
実行使用メモリ 326,656 KB
最終ジャッジ日時 2024-04-24 15:00:44
合計ジャッジ時間 22,370 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 7 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 5 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 171 ms
24,192 KB
testcase_11 AC 7 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 9 ms
5,376 KB
testcase_16 AC 3,537 ms
290,688 KB
testcase_17 AC 15 ms
5,376 KB
testcase_18 AC 8 ms
5,376 KB
testcase_19 AC 14 ms
5,376 KB
testcase_20 AC 3 ms
5,376 KB
testcase_21 AC 3,658 ms
305,024 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 3,809 ms
310,912 KB
testcase_24 AC 3,642 ms
261,760 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 4,021 ms
326,656 KB
testcase_27 AC 78 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 3 ms
5,376 KB
testcase_30 AC 2 ms
5,376 KB
testcase_31 AC 24 ms
5,376 KB
testcase_32 AC 78 ms
5,376 KB
testcase_33 AC 110 ms
5,376 KB
testcase_34 AC 57 ms
5,376 KB
testcase_35 AC 56 ms
5,376 KB
testcase_36 AC 110 ms
5,376 KB
testcase_37 AC 109 ms
5,376 KB
testcase_38 AC 31 ms
5,376 KB
testcase_39 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <unordered_map>

using namespace std;
using ll = long long;

#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

vector<ll> f(ll N) {
    vector<ll> vs;
    for (ll i = 2; i * i <= N; i++) {
        while (N % i == 0) {
            vs.push_back(i);
            N /= i;
        }
    }
    if (N != 1) vs.push_back(N);
    return vs;
}

map<tuple<int, ll, ll, ll>, ll> dp;

ll dfs(int idx, ll t1, ll t2, ll t3, vector<ll> &vs) {
    if (idx == vs.size()) return t1 + t2 + t3 - 3;
    auto s = tie(idx, t1, t2, t3);
    if (dp.count(s)) return dp[s];
    //printf("debug: %d %lld %lld %lld\n", idx, t1, t2, t3);
    ll res = dfs(idx + 1, t1 * vs[idx], t2, t3, vs);
    res = min(res, dfs(idx + 1, t1, t2 * vs[idx], t3, vs));
    res = min(res, dfs(idx + 1, t1, t2, t3 * vs[idx], vs));

    return dp[s] = res;
}

int main() {
    ll N;
    cin >> N;
    auto vs = f(N);
    //cout << vs.size() << endl;
    ll ans = 0;
    /*
    while (vs.size()) {
        auto it = vs.begin();
        rep(i, 3) {
            if (it == vs.end()) break;
            t[i] *= *it;
            it = vs.erase(it);
        }
        reverse(all(vs));
    }
    rep(i, 3) ans += t[i] - 1;
    */
    ans = dfs(0, 1, 1, 1, vs);
    cout << ans << " " << N - 1 << endl;
    return 0;
}
0