Java implementation is way slower than C++ one

Revision en1, by beginner1010, 2019-11-09 02:05:15

Today, I tried problem G from Education Round 45. My java implementation (64550159) gets time limit exceeded. It takes at least 4500 ms on test 5 while the same C++ implementation (64545259) on that test case takes only 600 ms.

I tried different things to optimize the Java implementation, but none could help. I believe there is something tricky that I am missing. I appreciate if you let me know which part of my Java implementation affects the overall performance.

BTW, in the C++ implementation, I used an array instead of queue<int>. I found queue so slow which causes time limit exceeded.

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English beginner1010 2019-11-09 02:05:15 814 Initial revision (published)