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

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

Arranging Shoes

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

요약
n쌍의 왼발, 오른발 신발이 일렬로 놓여 있을 때, 각 쌍을 왼발이 먼저 오도록 나란히 묶는 데 필요한 인접 교환의 최솟값을 구한다.
난이도

보통10점 중 5점

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

문제

Adnan owns the biggest shoe store in Baku. A box containing nn pairs of shoes has just arrived at the store. Each pair consists of two shoes of the same size: a left and a right one. Adnan has put all of the 2n2n shoes in a row consisting of 2n2n positions numbered 00 through 2n−12n-1 from left to right.

Adnan wants to rearrange the shoes into a valid arrangement. An arrangement is valid if and only if for every ii (0≤i≤n−10 \leq i \leq n-1), the following conditions hold:

  • The shoes at positions 2i2i and 2i+12i+1 are of the same size.
  • The shoe at position 2i2i is a left shoe.
  • The shoe at position 2i+12i+1 is a right shoe.

For this purpose, Adnan can make a series of swaps.

In each swap, he selects two shoes that are adjacent at that moment and exchanges them (i.e., picks them up and puts each one on the former position of the other shoe).

Two shoes are adjacent if their positions differ by one.

Determine the minimum number of swaps that Adnan needs to perform in order to obtain a valid arrangement of the shoes.

제한

  •  1≤n≤100,0001 \leq n \leq 100\\,000 
  • For each ii (0≤i≤2n−10 \leq i \leq 2n-1), 1≤∣S\[i]∣≤n1 \leq |S\[i]| \leq n.
  • A valid arrangement of the shoes can be obtained by performing some sequence of swaps.

예제

이 문제는 공개된 예제가 없습니다.