×

# SPOJ : BABY -java tle

 0 Hey, http://www.spoj.com/problems/BABY/ /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 484●9 accept rate: 10%

 0 hmm :| will have to switch to c for such tight time constraint problems answered 23 Dec '15, 18:48 484●9 accept rate: 10%
 1 nice explanation :) answered 23 Dec '15, 16:08 5★deep1996 66●1 accept rate: 16%
 4 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 : - https://www.codechef.com/viewsolution/8884493 (got TLE) C solution : - https://www.codechef.com/viewsolution/8884719 (got accepted) Better idea would be - you may go for C,C++ for such problems. Happy coding. :) answered 21 Dec '15, 19:45 781●8 accept rate: 7%
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• 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:

×36
×24
×18
×3

question asked: 21 Dec '15, 19:00

question was seen: 1,787 times

last updated: 23 Dec '15, 18:48