Partially Correct Answer--------**can you plz tell test case which fails**


#1

can you plz tell test case which is failing

  • Wrong Answer. Your program’s output doesn’t match the expected output. You can try testing your code with custom input and try putting debug statements in your code.

  • Your code might be failing for larger test-cases


vector<vector > v;
vector<vector > v2;
vector b, rt;
int a, n;

long check(long x){
if(x == INT_MAX) return 0;
else return x;
}

long run(vector ck, int s, int e, int ls, int le){
if((e - s) <= 0) return 0;
if(v[s][e] != INT_MAX) return v[s][e];

long x = INT_MAX, y, z, rs = INT_MAX;
for(int i = s; i < e; i++){
    if( !ck[i] ){
        ck[i] = 1;
        y = check( run(ck, s, i, ls, b[i]) );
        z = check( run(ck, i + 1, e, b[i], le) );
        
        rs = min(x, (z + y + (le - ls)));    
        v2[s][e] = ((x == rs)?v2[s][e] : i);
        x = rs;
        ck[i] = 0;
    }
}
v[s][e] = x;
return x;

}

int iter = 0;
void find(int sum, int s, int e){
if(e == INT_MAX || s == INT_MAX || v2[s][e] == INT_MAX || iter >= n){
iter–;
return ;
}

int mid = v2[s][e];
rt[iter] = b[ mid ];

iter++;
    find(v2[mid + 1][e], s, mid);
iter++;
    find(v2[s][mid], mid + 1, e);

}

vector Solution::rodCut(int A, vector &B) {
sort(b.begin(), b.end());

b.clear();      rt.clear();     v.clear();     v2.clear();
b = B;    a = A;    n = b.size();   iter = 0;
rt.resize(n, -1);
v.resize(n + 1, vector<long long>(n + 1, INT_MAX));
v2.resize(n + 1, vector<long long>(n + 1, INT_MAX));

vector<bool> ck(n, 0);

int x = run(ck, 0, n, 0, A);
find( x, 0, n );

return rt;

}


#2

Use unsigned long long when creating dp array. it worked for me


#3

thanks man!! This worked for me as well.