My program passed all sample tests from this phorum, but I have WA. Why?
Posted by
sanok 12 Dec 2005 00:01
#include <iostream.h>
#include <stdlib.h>
int N;
int aWeight[20];
int p2[20]={1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65536,131072,262144,524288};
int S,SL,minD;
int main()
{
cin >> N;
S=0;
for(int i=0;i<N;i++)
{
cin>>aWeight[i];
S+=aWeight[i];
}
minD=S;
for(int i=0;i<p2[N];i++)
{
SL=0;
for(int d=0;d<N;d++)
if(i & p2[d])
SL+=aWeight[d];
if(abs(S-2*SL) < minD)
minD = abs(S-2*SL);
}
cout<<minD;
}
Re: My program passed all sample tests from this phorum, but I have WA. Why?
Add 1048576 to array p2 and you'll get AC.
(Let N=20 then ...)
Re: My program passed all sample tests from this phorum, but I have WA. Why?
Posted by
sanok 12 Dec 2005 03:07
Oh! Thanks a lot. Now it works!