为什么下载的测试数据都过了,但为什么RE了?
查看原帖
为什么下载的测试数据都过了,但为什么RE了?
1183187
sxhy楼主2024/3/13 22:34
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 100000000;
int v,n,g[N],r1,h1,res=1e9,minv[N],mins[N];

int dfs(int ce, int s, int now, int r, int h)
{   
    
    if (ce == 0)
    {
        
        if (v == now) {
            res = min(s,res);
        }
        return 0;
    }
    
    if (s + 2 * (v - now) / r > res)return 0;
    if (v< now+minv[ce]||res<=s+mins[ce])return 0;
    for (int i =r-1; i >= ce;i--) {
        for (int j =min(h-1,(v-now)/(i*i)); j >= ce; j--) {
            int t=0;
            if (ce == n)t = i * i;
            dfs(ce -1, s + 2 * i * j+t, now+i * i * j ,i , j );

        }
    }
    
}

int main() {
  
    cin >> v >> n;
    for (int i = 1; i <= n; i++)
    {
        minv[i] =minv[i-1]+ i * i * i;
        mins[i] = mins[i - 1] + 2 * i * i;
    }
    r1=sqrt(v);
    h1= 1e9;
    dfs(n,0,0,r1,h1);
    if (res == 1e9)cout << "0";
    else 
    cout << res;
}
2024/3/13 22:34
加载中...