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

11232번 - Shuffles 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 256 MB78333345.205%

문제

The most common technique for shuffling a deck of cards is called the Riffle or Dovetail shuffle. The deck is split into two stacks, which are then interleaved with each other. The deck can be split anywhere, and the two stacks can be interleaved in any way.

For example, consider a deck with 10 unique cards:

1 2 3 4 5 6 7 8 9 10

Split them somewhere:

1 2 3 4 5 6 7 8 9 10

And interleave them in some way:

1 2 7 3 8 9 4 5 10 6

Do it again. Split them somewhere:

1 2 7 3 8 9 4 5 10 6

And interleave them in some way:

3 8 1 9 4 5 2 7 10 6

This is one possible ordering after 2 shuffles. Suppose there are n unique cards, and that they start out perfectly ordered: 1, 2, 3, ..., n. Given an ordering of the deck, what is the smallest number of shuffles that could possibly put the deck in that order?

입력

Each input will consist of a single test case. Note that your program may be run multiple times on different inputs. Each test case will begin with a single integer n (1 ≤ n ≤ 1,000,000) indicating the number of cards in the deck. On the next line will be n unique integers c (1 ≤ c ≤ n), with a single space between them, indicating an ordering of the n cards. The values c are guaranteed to be a permutation of the numbers 1..n.

출력

Output a single line with a single integer indicating the minimum number of shuffles that could possibly put the deck in the given order. Output no spaces.

제한

예제 입력 1

10
1 2 7 3 8 9 4 5 10 6

예제 출력 1

1

예제 입력 2

10
3 8 1 9 4 5 2 7 10 6

예제 출력 2

2

예제 입력 3

8
2 1 4 3 6 5 8 7

예제 출력 3

3

힌트

출처

ICPC > Regionals > North America > Southeast USA Regional > 2014 Southeast USA Regional Programming Contest > Division 1 H번

ICPC > Regionals > North America > Southeast USA Regional > 2014 Southeast USA Regional Programming Contest > Division 2 H번

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

출처

대학교 대회

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

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