Submission #20735986


Source Code Expand

Copy
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std;
void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
            ∧_∧
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     @hamayanhamayan0
    /   \     | |
    /   / ̄ ̄ ̄ ̄/  |
  __(__ニつ/     _/ .| .|____
     \/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/














int N, M, A[2010101];
//---------------------------------------------------------------------------------------------------
int cnt[2010101];
bool check(int limit) {
	rep(i, 0, N) cnt[i] = 0;
	int placed = 0;
	rep(i, 0, M) {
		if (cnt[A[i]] == 0 && A[i] <= limit) placed++;
		cnt[A[i]]++;
	}
	if (placed <= limit) return true;
	rep(i, M, N) {
		if (cnt[A[i - M]] == 1 && A[i - M] <= limit) placed--;
		cnt[A[i - M]]--;
		if (cnt[A[i]] == 0 && A[i] <= limit) placed++;
		cnt[A[i]]++;

		if (placed <= limit) return true;
	}

	return false;
}
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> M;
	rep(i, 0, N) cin >> A[i];
	
	int ng = -1, ok = N;
	while (ng + 1 != ok) {
		int md = (ng + ok) / 2;
		if (check(md)) ok = md;
		else ng = md;
	}
	cout << ok << endl;
}





Submission Info

Submission Time
Task E - Mex Min
User hamayanhamayan
Language C++ (GCC 9.2.1)
Score 500
Code Size 2166 Byte
Status AC
Exec Time 239 ms
Memory 15272 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 4
AC × 28
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt
All answer_n_00.txt, answer_n_01.txt, gu_killer_00.txt, gu_killer_01.txt, gu_killer_02.txt, handmade_00.txt, handmade_01.txt, handmade_02.txt, handmade_03.txt, large_answer_00.txt, large_answer_01.txt, large_answer_02.txt, large_answer_03.txt, large_answer_04.txt, large_answer_05.txt, large_answer_06.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, same_00.txt, same_01.txt, sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt
Case Name Status Exec Time Memory
answer_n_00.txt AC 239 ms 15256 KB
answer_n_01.txt AC 114 ms 9624 KB
gu_killer_00.txt AC 138 ms 15224 KB
gu_killer_01.txt AC 152 ms 15224 KB
gu_killer_02.txt AC 142 ms 15220 KB
handmade_00.txt AC 2 ms 3508 KB
handmade_01.txt AC 2 ms 3436 KB
handmade_02.txt AC 3 ms 3544 KB
handmade_03.txt AC 2 ms 3444 KB
large_answer_00.txt AC 138 ms 15256 KB
large_answer_01.txt AC 158 ms 15272 KB
large_answer_02.txt AC 143 ms 15168 KB
large_answer_03.txt AC 165 ms 15272 KB
large_answer_04.txt AC 71 ms 8836 KB
large_answer_05.txt AC 38 ms 5716 KB
large_answer_06.txt AC 111 ms 12016 KB
random_00.txt AC 99 ms 15216 KB
random_01.txt AC 108 ms 15216 KB
random_02.txt AC 89 ms 15168 KB
random_03.txt AC 87 ms 12476 KB
random_04.txt AC 77 ms 9392 KB
random_05.txt AC 8 ms 3816 KB
same_00.txt AC 112 ms 15224 KB
same_01.txt AC 161 ms 15204 KB
sample_01.txt AC 2 ms 3500 KB
sample_02.txt AC 2 ms 3508 KB
sample_03.txt AC 2 ms 3504 KB
sample_04.txt AC 2 ms 3508 KB