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

18494번 - Petr’s Algorithm 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 512 MB91594669.697%

문제

Petr is well-known for his unusual contests which shuffle well-established standings a lot. Each of his contests has a positive integer parameter k: its unusualness.

To predict results of such a contest with n participants, we can use the following algorithm: take an identity permutation of length n: p1 = 1, p2 = 2, . . . , pn = n and then sequentially shuffle all segments of length k from left to right.

In other words, we perform (n − k + 1) operations, where on the i-th operation we permute elements pi, pi+1, . . . , pi+k−1 in random order so that all the permutations of these elements are equiprobable.

Given the resulting permutation p, can you recover the unusualness parameter k of this particular Petr’s contest? To make things easier, we will only give you such tests that 20k ≤ n holds.

입력

The first line contains a single integer n (40 ≤ n ≤ 105) — the length of the permutation.

The second line contains n distinct integers p1, p2, . . . , pn (1 ≤ pi ≤ n) — the resulting permutation. It is guaranteed that this permutation was generated using the algorithm described above for some k such that 20k ≤ n.

출력

Print a single integer — the unusualness parameter k of this particular Petr’s contest.

제한

예제 입력 1

40
2 3 4 1 6 5 8 9 7 11 10 12 14 13 15 17 18 16 19 20 21 23 22 25 26 24 28 27 30 29 32 33 31 35 36 37 38 34 40 39

예제 출력 1

2

힌트

출처

Camp > Petrozavodsk Programming Camp > Winter 2020 > Day 8: Almost Algoritmic Contest G번

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

출처

대학교 대회

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

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