Editorial for SAC '22 Code Challenge 4 P5 - Obligatory Interactive Problem


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.

Author: maxcruickshanks

Subtask 1

It suffices to count inversions by iterating over all pairs of indices (including j<i).

Time Complexity: O(N2)

Query Count: N(N1)

Subtask 2

Optimize the subtask 1 solution by iterating over all pairs of indices excluding ji.

Time Complexity: O(N2)

Query Count: N(N1)2

Subtask 3

This subtask was intended to reward solutions that use a heuristic that has a bad query constant.

Subtask 4

First, query Q2 heights. If there are more Q2 queries than people, output the permutation.

For the heights that were not found in the Q2 queries, insert them into an array and sort it with any built-in function but create a custom comparator to interact with the grader.

After sorting it, output the permutation.

Time Complexity: O(NlogN)

Query Count: min(N,Q2)+max(0,(NQ2)log(NQ2))

Note that other solutions that use probabilistic lemmas also suffice since the grader is not adaptive.


Comments

There are no comments at the moment.