Confusion regarding time limit

One of my code on ideone gives 0.11 seconds.
(Java code using biginteger class), but here on codechef gives TLe.
I m bit confused regarding this, please can someone sort this.

The running time of your code is directly proportional to size and nature of input. You cannot be sure that your input will be of the same size as that in the actual test cases. Hence TLE.

I checked on ideone with the largest limit of the constraints given
and it then gives 0.11 sec.

And http://ideone.com/WHBvfb code on ideone shows 0.1 sec but on codechef here gives Tle. How this is happening …i m confused even more now! (For the MTRICK problem - jan challenge)

@damn_me You have given input strings of length 2 and 3. In the worst case there will be 30 test cases of input string of length 1000! Your algorithm is highly inefficient as you are actually reversing, multiplying and adding each time. Have a look at the editorial and you will see how it is actually solved.

1 Like

@kcahdog Yeah… I know this is inefficient. Even i did some other way in contest(however that is giving WA). But what i am concerned about is when the solution gives 0.1 for the highest possible value, then how come TLE?

You have considered the highest possible value of a,b and c whereas the time complexity of your code is solely dependent on n, the length if the string. Try giving input with n=1000 and you will see why you get TLE

@kcahdog Oh yess!! Exactly, thanks!