Hey,
SPOJ.com - Problem 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) ??
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 : - CodeChef: Practical coding for everyone (got TLE)
C solution : - CodeChef: Practical coding for everyone (got accepted)
Better idea would be - you may go for C,C++ for such problems.
Happy coding.
4 Likes
nice explanation
1 Like
hmm
will have to switch to c for such tight time constraint problems