Universal Cup Judging System

Universal Cup

Time Limit: 2.0 s Memory Limit: 1024 MB Total points: 100 Hackable ✓
Statistics

문제 설명

정수 $N$과 $X$, 그리고 길이가 $N$인 정수열 $A = (A_1, A_2, \dots, A_N)$이 주어집니다. 다음 조건을 모두 만족하는 길이가 $N$인 정수열 $s = (s_1, s_2, \dots, s_N)$을 구성하려고 합니다.

  • $1 \le s_i \le X$
  • $s_i \neq A_i$ ($1 \le i \le N$)

$s_i = s_{i+1}$을 만족하는 인덱스 $i$ ($1 \le i < N$)의 개수의 최댓값을 구하세요.

입력

입력은 다음 형식으로 주어집니다:

N X
A_1 A_2 ... A_N
  • $1 \le N \le 5 \times 10^5$
  • $2 \le X \le 10^9$
  • $1 \le A_i \le X$ ($1 \le i \le N$)
  • 입력으로 주어지는 모든 값은 정수입니다.

출력

답을 출력하세요.

예제

예제 입력 1

8 3
1 2 2 3 2 1 2 1

예제 출력 1

5

예제 입력 2

4 8
7 6 3 8

예제 출력 2

3

노트

첫 번째 테스트 케이스에서 예를 들어 $s = (3, 3, 1, 1, 3, 3, 3, 3)$으로 정하면, $s_i = s_{i+1}$을 만족하는 인덱스 $i$는 $1, 3, 5, 6, 7$로 총 $5$개입니다. 이보다 더 많은 인덱스에서 $s_i = s_{i+1}$이 성립하도록 할 수 없음을 보일 수 있으므로 답은 $5$입니다.

두 번째 테스트 케이스에서는 예를 들어 $s = (5, 5, 5, 5)$로 정할 수 있습니다.

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#1486EditorialOpen题解jianglyView
#1344EditorialOpen题解MilmonView

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.