C - Amidakuji Editorial by evima
For \(N \ge 3\), we have \(m_{\min} = 2\).
We restate part of the collapsed “More precisely” section from the problem statement.
For a sequence of permutations \(P=(P_1,P_2,\dots,P_m)\) of \((1,2,\dots,N)\), we call \(P\) a good sequence of permutations if the following condition is satisfied:
- For any permutation \(Q=(Q_1,Q_2,\dots,Q_N)\) of \((1,2,\dots,N)\), there exists a sequence of positive integers \(A=(A_1,A_2,\dots,A_k)\) satisfying all of the following conditions.
- \(0 \le k \le 2N^2\)
- All elements of \(A\) are between \(1\) and \(m\), inclusive.
- Starting from the sequence \(R=(1,2,\dots,N)\), performing the following operation for \(i = 1,2,\dots,k\) in order results in \(R = Q\).
- Let \(p = P_{A_i}\). Simultaneously replace \(R_{j}\) with \(R_{p_j}\) for each \(j = 1,2,\dots,N\).
We prove that preparing just one permutation cannot yield a good sequence of permutations. For this to work, the \(N\)-vertex \(N\)-edge graph with edges \(i \rightarrow P_{1,i}\) must be connected, but for any such permutation, only \(N\) permutations \(Q\) can be produced from \(P_1\). Since \(N! > N\) holds for \(N \ge 3\), we have \(m_{\min} \ge 2\).
We prove \(m_{\min} = 2\) along with a construction. We choose \(P_1,P_2\) as follows.
- \(P_1 = (2,1,3,4,\dots,N)\) (swap of the first and second elements)
- \(P_2 = (2,3,4,\dots,N,1)\) (left shift)
For simplicity, our goal is to reduce \(Q\) to \((1,2,\dots,N)\) by repeatedly applying the swap of the first and second elements and the left shift to \(Q\). In practice, we take the permutation \(q\) satisfying \(Q_{q_i} = i\) and sort \(q\).
Considering the application of bubble sort, \(Q\) can be sorted by the following algorithm.
- Repeat the following \(N\) times.
- For \(i = 1,2,\dots,N\), do the following.
- If \(i < N\) and \(Q_1 > Q_2\), swap \(Q_1\) and \(Q_2\).
- Left-shift \(Q\).
- For \(i = 1,2,\dots,N\), do the following.
It can be seen that the above executes the standard bubble sort. The number of operations is the number of inversions in \(Q\) for swaps, so at most \(\frac{N(N-1)}{2} + N^2\) in total.
The time complexity is \(\mathrm{O}(N^3)\) even if we spend \(\mathrm{O}(N)\) per application of \(P_1,P_2\) and per left-shift of \(Q\). It can also be reduced to \(\mathrm{O}(N^2)\) by applying bubble sort in a usual way.
posted:
last update: