Java: Arrays.sort(a); Size matters?

Revision en2, by EigenFunk, 2020-05-20 22:52:31

Solving 977C - Меньшие или равные I stumbled over a TLE:

Submission: 80761653

After digging into this I found out that the code gets accepted if the array is expanded by just one element.

Submission: 80762181

Ok, so when sorting an array the time needed for sorting obviously depends on the size of the array, but I'm really surprised to see that increasing the size by one might make the difference between '218ms' or TLE.

I did some local tests, there are some variations but not that significant.

So maybe a layer 8 problem? Am I missing something?

Edit: Not surprising others have written about this in more detail:

Even here by Flatfoot

I think I knew that sorting algorithms have best- and worst-case behaviors. It's just that I'm still blown away that corner cases are so close to 'average' behavior. And still I don't see a pattern which would have signaled this.

Tags java, sort, tle

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English EigenFunk 2020-05-20 22:52:31 762
en1 English EigenFunk 2020-05-20 15:43:16 710 Initial revision (published)