아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Limited Swaps

시간 제한2초메모리 제한1024 MB

요약
이웃한 두 수의 차가 2 이상일 때만 교환할 수 있을 때, 최대 20000번의 교환으로 처음 배열을 목표 배열로 바꾸거나 불가능을 판정한다.
난이도

보통10점 중 6점

유형
정렬, 그리디, 구현
정답자
아직 제출이 없습니다

문제

Lina is playing with nn cubes placed in a row. Each cube has an integer from 11 to nn written on it. Every integer from 11 to nn appears on exactly one cube.

Initially, the numbers on the cubes from left to right are a_1,a_2,…,a_na\_1, a\_2, \ldots, a\_n. Lina wants the numbers on the cubes from left to right to be b_1,b_2,…,b_nb\_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 22. This operation can be performed at most 20,00020\\,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 nn --- the number of cubes (1≤n≤1001 \le n \le 100).

The second line contains nn distinct integers a_1,a_2,…,a_na\_1, a\_2, \ldots, a\_n --- the initial numbers on the cubes from left to right (1≤a_i≤n1 \le a\_i \le n).

The third line contains nn distinct integers b_1,b_2,…,b_nb\_1, b\_2, \ldots, b\_n --- the desired numbers on the cubes from left to right (1≤b_i≤n1 \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-1.

Otherwise, in the first line, print a single integer kk --- the number of swaps in your sequence (0≤k≤20,0000 \le k \le 20\\,000).

In the second line, print kk integers s_1,s_2,…,s_ks\_1, s\_2, \ldots, s\_k describing the operations in order (1≤s_i≤n−11 \le s\_i \le n - 1). Integer s_is\_i stands for "swap the s_is\_i-th cube from the left with the (s_i+1)(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.

힌트

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

11 3,5‾\underline{3\\,5} 22 44 →\rightarrow 1,5‾\underline{1\\,5} 33 22 44 →\rightarrow 55 1,3‾\underline{1\\,3} 22 44 →\rightarrow 55 33 11 2,4‾\underline{2\\,4} →\rightarrow 5,3‾\underline{5\\,3} 11 44 22 →\rightarrow 33 55 11 44 22

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

예제2

  1. 예제 1

    입력
    5
    1 3 5 2 4
    3 5 1 4 2
    
    예상 출력
    5
    2 1 2 4 1
    
  2. 예제 2

    입력
    4
    1 2 3 4
    4 3 2 1
    
    예상 출력
    -1