A strange behaviour of sprintf() in c++ library



I just found strange thing about sprintf() (c++ library function).

have a look at these two solutions

[Time limit Exceeded solution][1]

[Accepted Solution][2]

the only difference between them is that, I used


in TLE solution,

in AC solution I replaced above sprintf() with


You can also observe that ACed solution took only 0.01s and 2.8MB memory

but TLE solution took around 11.8MB
[check here][3]

And one more thing program that gave TLE runs in 0s in [IDEONE][4] with extreme input data
so is it a bug in [CODECHEF][5] itself

Somebody please explain me is this a bug or some considerable unknown operation is happening here.

Thanks in advance.
[5]: http://www.codechef.com
[4]: http://ideone.com/e.js/jMhUVJ
[3]: http://www.codechef.com/status/FCTRL2?sort_by=All&sorting_order=asc&language=All&status=All&handle=hkbharath&Submit=GO
[2]: http://www.codechef.com/viewsolution/3938145
[1]: http://www.codechef.com/viewsolution/3938157


It is rather strange. Codechef and Ideone run on the same SPOJ server so i do not understand why this problem is happening.


Actually I got TLE for the same solution(which got TLE in CODECHEF) in SPOJ also…


I think it has something to do with the version of C++ used. I think different versions must have caused the problem