QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#546778#1955. Double Rainbowucup-team052#WA 0ms3896kbC++23876b2024-09-04 13:32:502024-09-04 13:32:51

Judging History

你现在查看的是最新测评结果

  • [2024-09-04 13:32:51]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3896kb
  • [2024-09-04 13:32:50]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

const int N = 10005;

int a[N], cnt[N], cnt2[N], r[N];
int n, k, all, all2;

void add(int x) {
	all += (cnt[x] == 0);
	++cnt[x];
	--cnt2[x];
	all2 -= (cnt2[x] == 0);
}

void del(int x) {
	--cnt[x];
	all -= (cnt[x] == 0);
	all2 += (cnt2[x] == 0);
	++cnt2[x];
}

int main() {
	scanf("%d%d", &n, &k);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
		++cnt2[a[i]];
	}
	for (int i = 1; i <= k; i++) all2 += (cnt2[i] > 0);
	int ans = n + 1;
	for (int i = 1; i <= n; i++) {
		r[i] = r[i - 1];
		while (r[i] < i) {
			++r[i];
			add(a[r[i]]);
		}
		while (r[i] < n && all < k) {
			++r[i];
			add(a[r[i]]);
		}
		if (all < k) r[i] = n + 1;
		if (r[i] != n + 1 && all2 == k) ans = min(ans, r[i] - i + 1);
		del(a[i]);
	}
	if (ans == n + 1) ans = -1;
	printf("%d\n", ans);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3896kb

input:

1 1
1

output:

-1

result:

wrong answer 1st lines differ - expected: '0', found: '-1'