結果
問題 | No.375 立方体のN等分 (1) |
ユーザー |
![]() |
提出日時 | 2016-06-07 15:10:00 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,654 bytes |
コンパイル時間 | 977 ms |
コンパイル使用メモリ | 100,964 KB |
実行使用メモリ | 35,456 KB |
最終ジャッジ日時 | 2024-10-08 17:19:18 |
合計ジャッジ時間 | 2,754 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 29 WA * 3 |
ソースコード
#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<int> f(ll N) { vector<int> 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<int> &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); ll t[3] = {1, 1, 1}; 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; }