beginner1010's blog

By beginner1010, history, 9 days ago, In English,

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.

 
 
 
 
  • Vote: I like it
  • +13
  • Vote: I do not like it

»
9 days ago, # |
  Vote: I like it +9 Vote: I do not like it

64553387
ArrayList sucks, boxing/unboxing also sucks, so sometimes you have to use something like /blog/entry/14328 or just primitive int arrays. Yeah, I know it's a bit ridiculous.

  • »
    »
    9 days ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Thanks a lot for providing the link to the blog. I was searching for similar thing for days.

  • »
    »
    9 days ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    Very interesting. I might need to make something like this in Kotlin one of these days

    Edit: One slight issue is that one of Kotlin's blessings, the extensive collection-manipulation library, becomes somewhat of a curse when rolling your own specialized collections. I find I'd basically have to rewrite what I need on the fly.