Universal Cup Judging System

Universal Cup

Time Limit: 1.5 s Memory Limit: 512 MB Total points: 100 Hackable ✓
Statistics

Ta định nghĩa $\operatorname{mex}(S)$ là số nguyên không âm nhỏ nhất không nằm trong tập hợp $S$.

Mayoi Hachikuji có một mảng $a$ gồm $n$ phần tử và cô muốn mảng này được sắp xếp theo thứ tự không giảm. Để làm vậy, cô có thể thực hiện thao tác sau một số lần tùy ý (có thể không lần nào):

  • Chọn số nguyên $i \in [1, \operatorname{length}(a) - 2]$ và thay thế $a_i, a_{i+1}, a_{i+2}$ bằng $\operatorname{mex}$ của chúng. Lưu ý rằng sau khi áp dụng thao tác này, độ dài của mảng giảm đi $2$.

Hãy tìm số thao tác tối thiểu mà Mayoi cần thực hiện để mảng được sắp xếp theo thứ tự không giảm. Trong trường hợp không thể thực hiện được, hãy in ra $-1$.

Dữ liệu vào

Dòng đầu tiên của dữ liệu vào chứa số nguyên $n$ ($2 \le n \le 5 \cdot 10^5$) — độ dài của mảng $a$.

Dòng tiếp theo chứa $n$ số nguyên $a_i$ ($0 \le a_i \le 10^9$) — các phần tử của mảng $a$.

Kết quả

In ra một số duy nhất — đáp án của bài toán.

Ví dụ

Dữ liệu vào 1

3
4 1 3

Kết quả 1

1

Dữ liệu vào 2

9
3 0 2 2 3 0 4 7 8

Kết quả 2

2

Dữ liệu vào 3

2
4 3

Kết quả 3

-1

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#1662EditorialOpenNew Editorial for Problem #14434louyuxuanView
#372EditorialOpen题解jianglyView

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.