Google Codejam 2011 Round 1B

I cannot believe how bad I perform at Google-organisated competitions. Today was the first online round of CodeJam. A started quite good, solved the first problem among the first hundreds.

But then came the second problem statement. I had the shape of the main idea (binary search the result) from the beginning, but I overesteemed myself. I forgot to consider the whole implementation in my mind. I forgot what was taught on our preparations for competitions: “turn of your monitor before you start typing the code!”.

When I was online (or on-coding, on-demand) resolving the subproblems the code just diverged. I have implemented a ternary_search (dividing the interval to 3 parts and choosing two of them) and using double type rather thqn int64. Of course, anger come on me. But I managed to implement the good solution at last. For my shame just after the Large request timeout. That was worth 15 points and because of that I finished 1052, just behind the line at 1000.
So, tomorow I will give a next try 🙂

Also I want to share a small problem:


#define EPSILON 0.0000001
if(to-from < EPSILON) do_something();

where to, from are double precision floating point variables. It was evaluated false even when from=to. My explanation is that 0.0000001 is stored in a float. The float epsilon is 1E-5, which is smaller. So EPSILON=0.0 when EPSILON is defined smaller as FLT_EPSILON. I have then solved my problem by transforming the condition:

if(to-from - EPSILON < 0.0) do_something();

We are always learning something new 🙂
So my experience from this competition is:

  • Do not haste
  • Have in mind that float/double is not a real number as in mathematics 🙂

I start feel the power of numberical analysis 🙂

Author: Peter Csiba

Software Engineer at Google

Leave a Reply

Your email address will not be published. Required fields are marked *