I’m getting a WA in the mixtures problem even though my question seems to run for all test cases.
I took the test cases present in SPOJ Discussion board and my program seems to work fine.Can anyone help me out?
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define ull unsigned long long
vector<int> v;
ull mem[100][100]={0};
ull smoke(int x,int y)
{
if(mem[x][y]!=0)
return mem[x][y];
if(x==y)
return 0;
ull ans=99999999;
int a,b;
for(int i=x;i<y;i++)
{
a=0;
for(int j=x;j<=i;j++)
a+=v[j];
a%=100;
b=0;
for(int j=i+1;j<=y;j++)
b+=v[j];
b%=100;
ans=min(ans,(smoke(x,i)+smoke(i+1,y)+a*b));
}
mem[x][y]=ans;
return ans;
}
int main()
{
std::ios::sync_with_stdio(false);
int n;
while(!cin.eof())
{
v.clear();
for(int i=0;i<100;i++)
for(int j=i;j<100;j++)
mem[i][j]=0;
cin>>n;
int temp;
for(int i=0;i<n;i++)
{
cin>>temp;
v.push_back(temp);
}
cout<<smoke(0,n-1)<<endl;
}
}