TCP - Editorial

Hi,

I tried solving the problem using the old school linear equation approach and finding the values of the constants a,b,c,d.The program executes well for the first test case but gives wrong answer for the second one,Can anyone advise where iam going wrong,PFB the link for my solution to the travelling chef problem
http://www.codechef.com/viewsolution/3785230

Did you find the roots of the given curve and then perform integration in blocks where function is monotonous?

How can the code be accepted if we just print any negative value. Here is the link:
http://www.codechef.com/viewsolution/3786107

4 Likes

Can anyone tell me why my solution is wrong.

After finding the constants . I am running a loop from 1 to T and in each loop I am finding the value of integration in range i-1 to i and adding the absolute sum in the answer . it is giving correct answer for the sample testcases.

My solution http://www.codechef.com/viewsolution/3785496

Thankyou…

I’ve submitted a lot of wrong solutions during the testing phase, some of them outputs negative values and didn’t get AC. May be that’s bacause of some wrong positive values. Anyway I will check checker.

1 Like

I used a very similar approach. I split the interval [0,T] into 5000 equal sub-intervals and I assumed that if the function has the same sign at both endpoints of a sub-interval then there is no root inside that interval - otherwise there is just one root. The reason for which I was quite sure that this would work was also the fact that the 4 given function values were integers, which made me assume that the roots of the function cannot be too close to each other.

2 Likes

Can someone please explain this code for the above problem http://www.codechef.com/viewsolution/3786481
What’s happening in this code…??

What’s correct in this code??? Why is it giving AC???


[1]


  [1]: http://www.codechef.com/viewsolution/3786836

This is the second version of the question i asked above… :stuck_out_tongue: However, I +1 for your statement “What’s correct in this code?”

I am having problem with precision …
After seeing @xellos0 solution that how he handled the precision I have changed my program . But still getting WA …Plz help !!
soln link http://www.codechef.com/viewsolution/3788126

The judge has been fixed and the submissions in practice section have been rejudged. The error occurred because I assumed that in the judge - first file was correct file and the second file was the user output. Turns out I was wrong.

So while calculating relative error, I was using this -
fabs(a-b)/a<=epsilon

Now since ‘a’ is negative (user output), the LHS will always be less than RHS. And hence negative solution got accepted.

Excuse me for my lack of knowledge.

3 Likes

So the correct way should have been fabs(a-b)/b<=epsilon. Right?

Yes, ‘b’ is in denominator.

@wittyceaser
can you please explain me the process of finding roots of the cubic polynomial and also tell me under which limits the intergration must be performed,thanks in advance!