포럼
문제 ICPC00397

M. Mex Hex

설명

The peace and quiet of your home city is being disturbed by the loud purrs and nightly creeping of a nearby magic bobcat. The mayor is sending you to scare it off – you are the city's Guardian for Collateral, Personal, and other Catastrophic Damages after all. You take on the challenge and prepare for scaring away the magnificent animal.

To defend itself against you, the magic bobcat (as the name suggests) tries to hurt you in unconventional ways. When it attacks, it casts a number of magic spells. Each spell is cast with a particular potential, which can be expressed as a natural number.For the purposes of this task, the natural numbers are defined as \(\mathbb N = \{0, 1, 2, \dots\}\). If you get hit with spells that have the potentials \(p_1, p_2, \dots, p_n\), then the pain that you will feel from them is \(\mathtt{mex}(\{p_1, p_2, \dots, p_n\})\), where \(\mathtt{mex}\) denotes the Minimum Excluded Value.Given a set \(S \subseteq \mathbb N, S \ne \mathbb N\), \(\mathtt{mex}(S)\) is the smallest number \(m \in \mathbb N\) that is not contained in \(S\). Note that the spells do not hurt you immediately. Only after all spells are cast will you feel the pain based on the \(\mathtt{mex}\) of their potentials.

To protect yourself, you bring a shield which can, also through magic, deflect the spells. Your shield has an activation duration \(d\), which means that when you activate the shield, the next \(d\) spells do not hit you. Afterwards, the shield must regenerate its magic and cannot be activated for the following \(d\) spells. Apart from that, you can activate the shield as often as you want. To ensure that you give the magic bobcat a good scare, the mayor requested that you sneak up to it. As the bobcat would spot the glow of your activated magic shield, the earliest time you can activate the shield is when you stand before the culprit, right before it casts the first spell.

You must now devise a tactic to sustain as little pain as possible. From studying the previous encounters with magic bobcats, you know the potentials of the spells that will be cast against you. What is the minimum pain you can receive from them if you activate your shield optimally?

제약
입력 형식

The input consists of:
- One line with two integers \(n\) and \(d\) (\(1 \leq n \leq 10^5\), \(1 \leq d \leq n\)), the number of spells and the activation duration of your shield.
- One line with \(n\) integers \(p_1, \dots, p_n\) (\(0 \leq p_i < n\)), the potentials of the \(n\) spells.

출력 형식

Output a single integer, the minimum pain you can receive from the spells.

예제 1
입력
5 1
0 1 0 1 0
출력
0
예제 2
입력
5 2
0 1 0 1 0
출력
2
예제 3
입력
14 2
8 1 1 0 0 2 0 1 2 1 0 6 4 2
출력
2
예제 4
입력
4 2
0 1 2 0
출력
1
문제 정보

생성자가 기록되지 않았습니다.

출처 ICPC GCPC 2025

평가 및 의견

M. Mex Hex

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 1 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

M. Mex Hex

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8