結果

問題 No.375 立方体のN等分 (1)
ユーザー odan3240odan3240
提出日時 2016-06-07 15:11:28
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,660 bytes
コンパイル時間 841 ms
コンパイル使用メモリ 99,244 KB
実行使用メモリ 35,456 KB
最終ジャッジ日時 2024-04-17 05:40:46
合計ジャッジ時間 2,496 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
権限があれば一括ダウンロードができます

ソースコード

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];
    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);
    for(auto e:vs) cout<<e<<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