11794 | 2024-11-11 10:37:35 | AGergo | Karácsonyi égők | cpp17 | Accepted 100/100 | 26ms | 1996 KiB |
#include <bits/stdc++.h>
using namespace std;
int main()
{
cin.tie(0);
iostream::sync_with_stdio(0);
int n, c;
cin >> n >> c;
vector<int> colors = vector<int>(n);
for(int i = 0; i < n; i++)
{
cin >> colors[i];
}
vector<int> ccount = vector<int>(c,false);
//worm :)
int l = 0, r = 0, len = n+1, counts = 0;
while(r < n)
{
//cout << l << ":" << r << " - " << colors[r] << ":" << ccount[colors[r]] << "\n";
if(ccount[colors[r]] == 0)
{
counts++;
}
ccount[colors[r]]++;
if(counts == c)
{
while(l<r)
{
ccount[colors[l]]--;
if(ccount[colors[l]] == 0)
{
counts--;
if(len > r-l)
{
len = r-l;
}
break;
}
l++;
}
}
r++;
}
cout << len+1;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 1ms | 320 KiB | ||||
2 | Accepted | 1ms | 320 KiB | ||||
subtask2 | 15/15 | ||||||
3 | Accepted | 16ms | 1084 KiB | ||||
4 | Accepted | 16ms | 1080 KiB | ||||
5 | Accepted | 16ms | 1080 KiB | ||||
6 | Accepted | 1ms | 320 KiB | ||||
7 | Accepted | 1ms | 320 KiB | ||||
subtask3 | 10/10 | ||||||
8 | Accepted | 1ms | 320 KiB | ||||
9 | Accepted | 1ms | 508 KiB | ||||
10 | Accepted | 1ms | 540 KiB | ||||
11 | Accepted | 1ms | 320 KiB | ||||
12 | Accepted | 1ms | 320 KiB | ||||
subtask4 | 20/20 | ||||||
13 | Accepted | 1ms | 320 KiB | ||||
14 | Accepted | 1ms | 380 KiB | ||||
15 | Accepted | 1ms | 320 KiB | ||||
16 | Accepted | 1ms | 320 KiB | ||||
17 | Accepted | 1ms | 320 KiB | ||||
subtask5 | 25/25 | ||||||
18 | Accepted | 1ms | 320 KiB | ||||
19 | Accepted | 1ms | 320 KiB | ||||
20 | Accepted | 1ms | 392 KiB | ||||
21 | Accepted | 1ms | 320 KiB | ||||
22 | Accepted | 1ms | 320 KiB | ||||
subtask6 | 30/30 | ||||||
23 | Accepted | 26ms | 1996 KiB | ||||
24 | Accepted | 19ms | 1260 KiB | ||||
25 | Accepted | 20ms | 1080 KiB | ||||
26 | Accepted | 24ms | 1228 KiB | ||||
27 | Accepted | 24ms | 1588 KiB | ||||
28 | Accepted | 21ms | 1016 KiB | ||||
29 | Accepted | 19ms | 1080 KiB | ||||
30 | Accepted | 16ms | 1084 KiB |