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

×

SPOJ : BABY -java tle

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

sanket407's gravatar image

4★sanket407
4849
accept rate: 10%


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

link

answered 23 Dec '15, 18:48

sanket407's gravatar image

4★sanket407
4849
accept rate: 10%

nice explanation :)

link

answered 23 Dec '15, 16:08

deep1996's gravatar image

5★deep1996
661
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 : - 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. :)

link

answered 21 Dec '15, 19:45

code_hard123's gravatar image

6★code_hard123
7818
accept rate: 7%

edited 21 Dec '15, 19:48

toggle preview
Preview

Follow this question

By Email:

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

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "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:

×36
×24
×18
×3

question asked: 21 Dec '15, 19:00

question was seen: 1,787 times

last updated: 23 Dec '15, 18:48