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


SPOJ : BABY -java tle

Hey, /n Tried a O(2^n * n^2) soln. Got TLE. Then found a cpp soln online of O(2^n * n). Implemented in java and got TLE . Implemented in C and the same soln passed . Tested both on ideone with n=16 . \n java runtime=0.17s c runtime = 0.03s \n Why is there so much diff in runtimes of java and c ? Is there a better approach to this problem (java passable) ??

asked 21 Dec '15, 19:00

sanket407's gravatar image

accept rate: 10%

hmm :| will have to switch to c for such tight time constraint problems


answered 23 Dec '15, 18:48

sanket407's gravatar image

accept rate: 10%

nice explanation :)


answered 23 Dec '15, 16:08

deep1996's gravatar image

accept rate: 16%

See you have to optimize your code a lot and have to use faster IO templates in JAVA for strict timelimit problems because JAVA is a slower language as compared to C/C++.

It takes much time in IO process.

Even i have faced such problems. Here it is.

JAVA solution : - (got TLE)

C solution : - (got accepted)

Better idea would be - you may go for C,C++ for such problems.

Happy coding. :)


answered 21 Dec '15, 19:45

code_hard123's gravatar image

accept rate: 7%

edited 21 Dec '15, 19:48

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: 21 Dec '15, 19:00

question was seen: 1,787 times

last updated: 23 Dec '15, 18:48