Description
Input
Output
Sample Input
1002
Sample Output
68
Hint
Source
//
// 17day6_I.cpp
// acm
//
// Created by sakumi on 19/02/2017.
// Copyright © 2017 sakumi. All rights reserved.
//
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
int min_volume[21];
int min_area[21];
int r[21];
int h[21];
int ans,n,m;
const int INF=0x3f3f3f3f;
void dfs(int r_limit,int h_limit,int volume,int area,int layer)
{
if(layer==0){
if(volume!=n)return;
ans=min(ans,area);
return;
}
if(area>ans-min_area[layer])return;
if(n-volume<min_volume[layer])return;
if(ans-area<=2*(n-volume)/r_limit)return ;
for(int i=r_limit;i>=layer;i--){
if(layer==m){
area=i*i;
}
int max_h=(n-min_volume[layer-1]-volume)/(i*i);
for(int j=min(max_h,h_limit);j>=layer;j--){
dfs(i-1,j-1,volume+i*i*j,area+2*i*j,layer-1);
}
}
}
int main()
{
while(scanf("%d",&n)!=EOF){
scanf("%d",&m);
min_area[0]=min_volume[0]=0;
for(int i=1;i<=20;i++){
min_area[i]=min_area[i-1]+2*i*i;
min_volume[i]=min_volume[i-1]+i*i*i;
}
ans=INF;
dfs((int)sqrt(n),n,0,0,m);
printf("%d\n",ans);
}
return 0;
}