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

25117번 - Sequence Conversion 2 서브태스크다국어

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

문제

You are given an array of non-negative integers $a_1, a_2, \dots, a_N$.

You can perform the following operation several times:

  • Choose an index $i$. (1ドル \leq i <$ length of the array) Then, remove $a_i, a_{i+1}$ and replace them with $a_i \oplus a_{i+1}$. (The total length of the array decreases by 1)

Expression $x \oplus y$ means bitwise xor of two numbers $x$ and $y$. In binary representation, if the $i$-th digit of x and y is equal, then the $i$-th digit of $x \oplus y$ is 0ドル,ドル and if not, it is 1ドル$.

The given operation exists in all modern programming languages. For example, in C++ and Java, it is represented as $x\ ^{\wedge}\ y$.

You want to convert the given array into a zig-zag array.

We say an array of $m$ integers, $z_1, z_2, ..., z_{m},ドル is a zig-zag array if no three consecutive elements in the array are either monotonically increasing or monotonically decreasing.

In other words, if there are three elements $z_i, z_{i+1}, z_{i+2}$ in the array such that $z_i \leq z_{i+1} \leq z_{i+2}$ or $z_i \geq z_{i+1} \geq z_{i+2},ドル the array is not zig-zag. Otherwise, it is zig-zag array.

Find the minimum number of operations needed to convert $\{a_i\}$ into a zig-zag array.

입력

The first line contains an integer $N,ドル where $N$ denotes the length of the sequence.

The second line contains $N$ space-separated non-negative integers $a_1, a_2, \dots, a_N$.

출력

Print the minimum number of operations needed to change the sequence $\{a_i\}$ into a zig-zag array.

제한

  • 1ドル \leq N \leq 3,000円$
  • 0ドル \leq a_i < 2^{30}$ $(1 \le i \le N)$

서브태스크 1 (20점)

This subtask has an additional constraint:

  • $N \le 20$

서브태스크 2 (30점)

This subtask has an additional constraint:

  • $N \le 100$

서브태스크 3 (50점)

This subtask has no additional constraints.

예제 입력 1

3
1 2 3

예제 출력 1

1

예제 입력 2

3
1 3 2

예제 출력 2

0

힌트

출처

University > KAIST > KAIST RUN Spring Contest > 2022 KAIST RUN Spring Contest D번

채점 및 기타 정보

  • 예제는 채점하지 않는다.
(追記) (追記ここまで)

출처

대학교 대회

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

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