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

26174번 - Alternating Algorithm 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
7 초 (추가 시간 없음) 1024 MB36191571.429%

문제

In recent years, CPU manufacturers have found it increasingly difficult to keep up with Moore's law of doubling the number of transistors on integrated circuit chips every two years. To address this, manufacturers have instead started creating CPUs with an increasingly higher number of cores. In fact, you just purchased a CPU with a staggering $n$ number of cores, no less!

Incidentally, you also have an array of $n+1$ integers, $a_0, a_1, \ldots, a_n,ドル that you need to sort. To make good use of the large number of cores on your CPU, you have devised a parallel sorting algorithm in which there is a dedicated core for comparing each adjacent pair of integers. As long as the array is not sorted in non-decreasing order, the algorithm proceeds in rounds that alternate between:

  • Odd rounds (starting with the first): The first core compares $a_0$ and $a_1,ドル the third core compares $a_2$ and $a_3,ドル the fifth core compares $a_4$ and $a_5,ドル and so on. If a pair of compared elements are out of order, the corresponding core will swap their positions. If $n$ is even, $a_n$ will be left untouched.
  • Even rounds: The second core compares $a_1$ and $a_2,ドル the fourth core compares $a_3$ and $a_4,ドル the sixth core compares $a_5$ and $a_6,ドル and so on. If a pair of compared elements are out of order, the corresponding core will swap their positions. If $n$ is odd, $a_n$ will be left untouched, and $a_0$ will be left untouched no matter what the parity of $n$ is.

Note that in both types of rounds some cores may be idle.

Before implementing this algorithm, you have decided to do some analysis. In particular, you noticed that the time complexity of the algorithm does not depend on the value of $n,ドル but rather it depends on the number of rounds that the algorithm runs. Given the initial contents of the array, determine the number of rounds that the parallel sorting algorithm runs before the array becomes sorted.

입력

The input consists of:

  • One line with an integer $n$ (1ドル \leq n \leq 4\cdot10^5$), the number of cores and the size of the array.
  • One line with $n+1$ integers $a_0, a_1, \ldots, a_n$ (0ドル \leq a_i \leq 10^9$ for each $i$), the initial contents of the array.

출력

Output the number of rounds that the parallel sorting algorithm runs before the array becomes sorted in non-decreasing order.

제한

예제 입력 1

3
8 13 4 10

예제 출력 1

3

예제 입력 2

5
13 12 14 10 14 12

예제 출력 2

3

예제 입력 3

2
2 2 1

예제 출력 3

3

힌트

출처

ICPC > Regionals > Europe > Northwestern European Regional Contest > NWERC 2022 A번

  • 문제를 만든 사람: Bjarki Ágúst Guðmundsson
(追記) (追記ここまで)

출처

대학교 대회

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

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