I am getting a wrong answer for the practice problem TREE PRODUCT. Can anyone tell me the problem with my solution? It seems to be a pretty straightforward question and I am quite sure the logic I am using is correct…
Is it possible, that for all inputs I tried:
3
1 2 4 2 4 5 999999999
3
1 2 4 2 4 999999999 999999999
3
1 2 4 2 999999999 999999999 999999999
3
1 2 4 999999999 999999999 999999999 999999999
0
the result is always the same - 999999975?
This is really strange
a[2*p] > a[2*p +1] ? a[p]=a[p]*a[2*p] : a[p]=a[p]*a[2*p +1];
Thanks for your reply. But the problem is not there i checked some accepted solutions . They are also giving the same output for your above input.
Sorry, I was too lazy, try this one
3
1000000000 1 100000 999999940 1 100000 1
0
should be 490 according to accepted solution…
now i am getting correct output for above case(there was problem in my
modulo operator. i have fixed that) but still i am getting wrong ans
my new solution http://www.codechef.com/viewsolution/4038646
You are not using mod for b array, it will overflow sooner or later…
So any suggestion how can i overcome this . i have used b array for finding whether left or right child is greater and applies modulus operator to array a elements.
problem is, that without mod it overflows, with mod it returns incorrect results, try to use double for b array…