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

26874번 - Limited Swaps 스페셜 저지다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 1024 MB68474670.769%

문제

Lina is playing with $n$ cubes placed in a row. Each cube has an integer from 1ドル$ to $n$ written on it. Every integer from 1ドル$ to $n$ appears on exactly one cube.

Initially, the numbers on the cubes from left to right are $a_1, a_2, \ldots, a_n$. Lina wants the numbers on the cubes from left to right to be $b_1, b_2, \ldots, b_n$.

Lina can swap any two adjacent cubes, but only if the difference between the numbers on them is at least 2ドル$. This operation can be performed at most 20ドル,000円$ times.

Find any sequence of swaps that transforms the initial configuration of numbers on the cubes into the desired one, or report that it is impossible.

입력

The first line contains a single integer $n$ --- the number of cubes (1ドル \le n \le 100$).

The second line contains $n$ distinct integers $a_1, a_2, \ldots, a_n$ --- the initial numbers on the cubes from left to right (1ドル \le a_i \le n$).

The third line contains $n$ distinct integers $b_1, b_2, \ldots, b_n$ --- the desired numbers on the cubes from left to right (1ドル \le b_i \le n$).

출력

If it is impossible to obtain the desired configuration of numbers on the cubes from the initial one, print a single integer $-1$.

Otherwise, in the first line, print a single integer $k$ --- the number of swaps in your sequence (0ドル \le k \le 20,000円$).

In the second line, print $k$ integers $s_1, s_2, \ldots, s_k$ describing the operations in order (1ドル \le s_i \le n - 1$). Integer $s_i$ stands for "swap the $s_i$-th cube from the left with the $(s_i + 1)$-th cube from the left".

You do not have to find the shortest solution. Any solution satisfying the constraints will be accepted.

제한

예제 입력 1

5
1 3 5 2 4
3 5 1 4 2

예제 출력 1

5
2 1 2 4 1

예제 입력 2

4
1 2 3 4
4 3 2 1

예제 출력 2

-1

노트

In the first example test, the configuration of numbers changes as follows:

1ドル$ $\underline{3,5円}$ 2ドル$ 4ドル$ $\rightarrow$ $\underline{1,5円}$ 3ドル$ 2ドル$ 4ドル$ $\rightarrow$ 5ドル$ $\underline{1,3円}$ 2ドル$ 4ドル$ $\rightarrow$ 5ドル$ 3ドル$ 1ドル$ $\underline{2,4円}$ $\rightarrow$ $\underline{5,3円}$ 1ドル$ 4ドル$ 2ドル$ $\rightarrow$ 3ドル$ 5ドル$ 1ドル$ 4ドル$ 2ドル$

In the second example test, making even a single swap in the initial configuration is impossible.

출처

ICPC > Regionals > Northern Eurasia > Northwestern Russia Regional Contest > ICPC 2022-2023 North-Western Russia Regional Contest L번

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

출처

대학교 대회

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

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