結果
| 問題 |
No.376 立方体のN等分 (2)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-12-07 20:18:27 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,402 bytes |
| コンパイル時間 | 1,882 ms |
| コンパイル使用メモリ | 182,192 KB |
| 実行使用メモリ | 245,760 KB |
| 最終ジャッジ日時 | 2024-11-28 03:27:54 |
| 合計ジャッジ時間 | 21,729 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 34 WA * 4 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
vector<ll> factorize(ll n)
{
vector<ll> ret;
ll t=n;
for(ll i=2; i*i<=n; ++i)
{
while(t%i==0)
{
t/=i;
ret.pb(i);
}
}
if(t>1) ret.pb(t);
sort(all(ret),greater<ll>());
return ret;
}
const ll INF=12345678901234LL;
vector<ll> d;
int D;
vector<ll> m;
typedef pair<ll,ll> pl;
typedef pair<int,pl> P;
map<P,ll> dp;
ll dfs(int now, ll a, ll c)
{
ll b = m[now]/a/c;
if(!(a<=b && b<=c)) return INF;
if(now==D) return a+b+c-3;
P state(now,pl(a,c));
if(dp.find(state) != dp.end()) return dp[state];
ll ret=INF;
ll na=a*d[now], nb=b*d[now], nc=c*d[now];
ret = min(ret, dfs(now+1, min({na,b,c}), max({na,b,c})));
ret = min(ret, dfs(now+1, min({a,nb,c}), max({a,nb,c})));
ret = min(ret, dfs(now+1, min({a,b,nc}), max({a,b,nc})));
dp[state]=ret;
return ret;
}
int main()
{
ll n;
cin >>n;
d=factorize(n);
D = d.size();
m = vector<ll>(D+1);
m[0]=1;
for(int i=1; i<=D; ++i) m[i]=m[i-1]*d[i-1];
cout << dfs(0,1,1) << " " << n-1 << endl;
return 0;
}