死于Sub3第一个点,Sub4最后一个点
#include <vector>
#include <iostream>
using namespace std;
int a[5010];
int sum[5010];
vector<int> cut;
int main()
{
int n, k;
cin >> n >> k;
int ans = 0;
cut.push_back(0);
for (int i = 1; i <= n; i++)
{
cin >> a[i];
if (a[i] == k)
{
cut.push_back(i);
}
}
cut.push_back(n + 1);
if (k == 0)
{
for (int i = 1; i <= n; i++)
{
if (a[i] != 0)
{
ans++;
}
}
cout << ans;
return 0;
}
if (k == 1)
{
for (int i = 1; i <= n; i++)
{
if (a[i] == 0)
{
ans++;
}
}
cout << ans;
return 0;
}
for (int x = 1; x < cut.size(); x++)
{
int sum_min = 10000;
for (int i = 0; i < 5001; i++)
{
sum[i] = 0;
}
for (int i = cut[x - 1] + 1; i < cut[x]; i++)
{
sum[a[i]]++;
}
for (int i = 0; i < k; i++)
{
sum_min = min(sum[i], sum_min);
}
ans += sum_min;
}
cout << ans;
return 0;
}
/*
10 5
0 0 1 1 2 2 3 3 4 4
*/
最后那组数据可以卡掉,不知道该怎么改