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

28233번 - Magic with Cards 다국어

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

문제

Mahsa has been practicing shuffling cards for a few months now. Tonight, she finally decided to invite her friends over and show off her new skills. So she picks up a deck with 2n cards, shows her friends the face of the cards whithout changing the deck order and asks someone to pick two positions i and j in the deck. Then, she tells everyone that she is going to move the card in the i-th position to the j-th position by applying only two types of shuffles.

Assume the cards in the deck are ⟨c1, c2, ..., c2n⟩. Mahsa can perform these two shuffles as many times as she wants:

Riffle: Divide the cards into two parts⟨c1, c2, ..., cn⟩ and ⟨cn+1, ..., c2n⟩ and produce ⟨c1, cn+1, c2, cn+2, ..., cn, c2n⟩.

Scuffle: From ⟨c1, c2, ..., c2n⟩, produce ⟨c2, c1, c4, c3, ..., c2n, c2n-1⟩.

Help Mahsa find out the minimum number of shuffles she needs, and she’ll figure out the rest.

입력

The input consists of a single line containing three space-separated integers n, i and j (1 ⩽ n ⩽ 105 and 1 ⩽ i, j ⩽ 2n).

출력

Print a single integer, the minimum number of shuffles required to bring the i-th card to j-th position. If it is not possible to do so, print -1 instead.

제한

예제 입력 1

4 3 8

예제 출력 1

3

예제 입력 2

5 4 1

예제 출력 2

5

예제 입력 3

1 1 1

예제 출력 3

0

힌트

출처

ICPC > Regionals > Asia West Continent > Iran > 2022 ICPC Asia Tehran Regional Contest J번

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

출처

대학교 대회

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

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