Problem: Array Stabilization

Revision en3, by MZuenni, 2018-12-27 23:47:01

Hello guys, for all those who message me here on codeforces, i cant reply since i have reached my daily message quota...

Now to the Hack for todys Div. 3 B. 1095B - Array Stabilization


For those who tried to solve this problem in java and Arrays.sort() and got hacked, you need to know that this method implements a deterministic dual pivot quicksort for primitive types like int. This maybe doesn't sounds bad, but it is! A deterministic quicksort is only on random input data in , but its worst case behaviour is still . Therefore it is possible to find inputs where you will get TLE (like in my hack).

There is a generator for this from dalex generator, and many problem setters know about this an can build such testcases.

There are however many ways to fix this here i will list some examples:

  • use Integer[] instead of int[]
  • use Arraylist and Collections.sort()
  • use shuffle the int[] before sorting it
Tags java, anti-quicksort

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en3 English MZuenni 2018-12-27 23:47:01 0 (published)
en2 English MZuenni 2018-12-27 23:45:21 221 (saved to drafts)
en1 English MZuenni 2018-12-27 23:36:45 894 Initial revision (published)