Editorial for DMOPC '18 Contest 1 P2 - Sorting
Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.
Submitting an official solution before solving the problem yourself is a bannable offence.
Author:
For of points, we have . If , then the list can be sorted for sure. If , then we can separate the list into elements with even and odd indices, sort those lists, and check if alternating between the two lists yields a sorted list.
Time Complexity:
For the remaining of points, we can check if , for all , . This is because in the sorted list, , and the th element can only be swapped with elements that are equivalent modulo .
Time Complexity:
Comments