Editorial for DMOPC '22 Contest 2 P3 - Good Permutations
Submitting an official solution before solving the problem yourself is a bannable offence.
Author:
Hint 1
Consider solving this problem if the target permutation is an identity permutation.
Hint 2
Consider the relative ordering of elements in the final answer.
Hint 3
Graph Theory
Hint 4
Topological Sorting
Solution Idea
Consider which types of elements can't be swapped, and what that means for the final permutation. If two elements at positions
Subtask 1
For this subtask, iterate through all possible pairs of elements
Hint 1 for Full Solution
How can we reduce the number of edges?
Hint 2 for Full Solution
Consider the factors of each element.
Full Solution
For the full solution, we need a way to reduce the number of edges in the graph. The key insight is that not all edges are necessary. Consider three indices
Using our subtask 1 solution, we would draw edges
Consider iterating through all elements from left to right. For each prime factor
Note from the author
Originally, the problem was just the identity permutation as the target. Credits to
for suggesting the current version of this problem.
Comments