DMPG '17 B4 - Bad Sort

View as PDF

Submit solution

Points: 7
Time limit: 0.6s
Memory limit: 64M

Problem type
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

Roger is teaching his CS club how to sort! This algorithm looks like this:

function sort(A[0 .. N - 1]):
    if A is not empty:
        pivot <- A[N/2]
        lesser <- []
        equal <- []
        greater <- []
        for each a in A:
            if a < pivot:
                append a to lesser
            if a = pivot:
                append a to equal
            if a > pivot:
                append a to greater
        A <- lesser + equal + greater

However, you think that Roger is inferior to Kirito, and that his sort has a devastating flaw! Can you generate a worst case?

Input Specification

There is no input.

Output Specification

Print 1\,024 integers, each on a newline, representing a worst-case scenario for the sorting algorithm.


  • 12
    kipply  commented on May 22, 2017, 2:02 p.m.

    This is funny because Roger is Kirito

  • 0
    Ninjaclasher  commented on May 16, 2017, 7:34 p.m.

    Any hints? Is this a problem with actual function code, or does it have something to do with manipulating numbers in a specific way?