You are not logged in. Please login at to post your questions!


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

Accepted Solution

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

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

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

Thanks in advance.

asked 25 May '14, 00:41

hkbharath's gravatar image

accept rate: 9%

edited 25 May '14, 01:56

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


answered 25 May '14, 01:18

kcahdog's gravatar image

accept rate: 14%

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

(25 May '14, 01:58) hkbharath3★

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

(25 May '14, 04:02) kcahdog3★
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:


question asked: 25 May '14, 00:41

question was seen: 1,939 times

last updated: 25 May '14, 04:02