Блог пользователя insane_banda

Автор insane_banda, история, 5 лет назад, По-английски

So I just found out that my solution which is almost same as this one gets TLE on test case 8 while latter got AC.

I can't figure-out why this happened?

Problem link -> C.Save More Mice

Solution:

It turns out that Arrays.sort() in java uses Quicksort which has worst time complexity of O(n^2) and Collections.sort() uses that has time complexity of O(nlogn).

refer to this article for more information.

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

»
5 лет назад, скрыть # |
 
Проголосовать: нравится +9 Проголосовать: не нравится

Almost same != same

»
5 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

It's because of Arrays.sort which can run in quadratic time for some inputs.