Universal Cup Judging System

Universal Cup

Limite de temps : 1.5 s Limite de mémoire : 512 MB Points totaux : 100 Hackable ✓
Statistiques

Zdefiniujmy $\operatorname{mex}(S)$ jako najmniejszą nieujemną liczbę całkowitą, która nie należy do zbioru $S$.

Mayoi Hachikuji ma tablicę $a$ składającą się z $n$ elementów, którą chciałaby posortować w porządku niemalejącym. W tym celu może wykonać następującą operację dowolną liczbę razy (być może zero):

  • Wybierz liczbę całkowitą $i \in [1, \operatorname{length}(a) - 2]$ i zastąp elementy $a_i, a_{i+1}, a_{i+2}$ ich wartością $\operatorname{mex}$. Zauważ, że po wykonaniu tej operacji długość tablicy zmniejsza się o $2$.

Znajdź minimalną liczbę operacji, które Mayoi musi wykonać, aby tablica stała się posortowana w porządku niemalejącym. Jeśli jest to niemożliwe, wypisz $-1$.

Wejście

Pierwszy wiersz wejścia zawiera liczbę całkowitą $n$ ($2 \le n \le 5 \cdot 10^5$) — długość tablicy $a$.

Kolejny wiersz zawiera $n$ liczb całkowitych $a_i$ ($0 \le a_i \le 10^9$) — elementy tablicy $a$.

Wyjście

Wypisz jedną liczbę — odpowiedź dla zadania.

Przykłady

Przykładowe wejście 1

3
4 1 3

Przykładowe wyjście 1

1

Przykładowe wejście 2

9
3 0 2 2 3 0 4 7 8

Przykładowe wyjście 2

2

Przykładowe wejście 3

2
4 3

Przykładowe wyjście 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.