hunterr_196's blog

By hunterr_196, history, 6 years ago, In English

This is the ques from codechef for which i am getting TLE QUES and this is the link of my solution codesolution Please can anyone help me to understand why my approach is getting TLE all the time even though i am only performing the mathematical operations only. It would be a great help for me.

  • Vote: I like it
  • +3
  • Vote: I do not like it

| Write comment?
»
6 years ago, # |
  Vote: I like it +1 Vote: I do not like it

Here is the AC version of your code: Submission A few changes I made: 1) In your submission, almost every variable was a long double. In practice, double precision is enough for passing test cases. So, I tried changing long double to double, but it still couldn't pass. Maybe it was because there were too many floating point operations, which I think are more complicated and expensive than integer operations. So, except for a couple of variables, I changed them all to long longs. 2) Removed all the statements outputting anything to stderr via cerr. This outputting of data also consumes the runtime.

  • »
    »
    6 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    This solution with doubles passes too!

  • »
    »
    6 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    @roll_no_1 thank you buddy....its a great help from your side as i see many solutions of this problem but not able to find what's the mistake i am doing. You explained it very well by making some of the changes in my code only supplement with a nice explanation.

    • »
      »
      »
      6 years ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      I think you should also try to look at other faster solutions to see what improvement did they make, like in the one posted by ameya, I think the contestant reduced computational steps by doing a little more solving on paper by cancelling out common factors from the numerator and denominator, and that turned out to have a much better running time as compared to that of the optimizations that I made in your code.