Logo
(追記) (追記ここまで)

30297번 - Irreducible Permutation 스페셜 저지다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 (추가 시간 없음) 1024 MB15410910477.037%

문제

A permutation is called irreducible if none of its prefixes forms a permutation, except the permutation itself. For example, $[2,3,1]$ and $[4,1,2,3]$ are irreducible while $[2,1,3]$ and $[1,3,2]$ are not.

You are given a permutation $P$ of length $N$. In one operation, you can choose any two adjacent indices and swap their values.

Find the minimum number, and the corresponding sequence, of operations to transform $P$ into an irreducible permutation. It can be shown that you can always make given permutation irreducible.

입력

The first line contains a single integer $T$ --- the number of test cases.

The first line of each test case contains a single integer $N$.

The second line of each test case contains $N$ space-separated integers $P_1,\ldots ,P_N$ $(1\le P_i\le N)$.

출력

For each test case, print two lines:

On the first line, print $K$ --- the minimum number of operations that can make $P$ irreducible.

On the second line, print $K$ space-separated integers $S_1,\ldots ,S_K$ where $S_i$ and $S_i+1$ are the indices you intend to swap. If there are multiple solutions, you may print any.

Note that the operations are performed sequentially in the same order specified by your output.

제한

  • 1ドル\le T\le 100,円 000$
  • 1ドル\le N\le 100,円 000$
  • 1ドル\le P_i\le N\ (1\le i\le N)$
  • $P_i\neq P_j$ if $i\neq j\ (1\le i,j\le N)$
  • It is guaranteed that the sum of $N$ over all test cases does not exceed 500ドル,円 000$.
  • 1ドル\le S_i\le N-1\ (1\le i\le K)$

예제 입력 1

3
4
1 2 3 4
3
2 3 1
5
3 1 2 4 5

예제 출력 1

3
1 2 3
0
2
4 3

힌트

출처

University > KAIST > KAIST ICPC Mock Competition > 2023 KAIST 13th ICPC Mock Competition F번

Camp > Petrozavodsk Programming Camp > Summer 2024 > Day 2: K-ontest F번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /