4214 | 2023-03-16 17:33:55 | BalintGeza | Karácsonyi égők | cpp11 | Accepted 100/100 | 70ms | 7012 KiB |
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n, c, i;
cin>>n>>c;
vector<int> egok(n);
vector<int> szinek(c,-1); //indextabla
for(i=0;i<n;i++)
cin>>egok.at(i);
int hany=0; //a szinek vektor kitoltott elemeinek a szama
bool tele=false;
int kicsi, nagy, tav, kistav;
for(i=0;i<n;i++)
{
int szin=egok.at(i);
if(szinek.at(szin)==-1)
{
hany++;
szinek.at(szin)=i;
if(hany==c)
{
kicsi=*min_element(szinek.begin(),szinek.end());
nagy=*max_element(szinek.begin(),szinek.end());
tele=true;
tav=nagy-kicsi+1;
kistav=tav;
}
}
else if(!tele)
{
szinek.at(szin)=i;
}
else if(tele && szinek.at(szin)==kicsi)
{
szinek.at(szin)=i;
kicsi=*min_element(szinek.begin(),szinek.end());
nagy=*max_element(szinek.begin(),szinek.end());
tav=nagy-kicsi+1;
if(tav<kistav)
{
kistav=tav;
}
}
else if(tele)
{
szinek.at(szin)=i;
}
}
cout<<tav<<endl;
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1808 KiB | ||||
2 | Accepted | 3ms | 2056 KiB | ||||
subtask2 | 15/15 | ||||||
3 | Accepted | 37ms | 3624 KiB | ||||
4 | Accepted | 37ms | 3836 KiB | ||||
5 | Accepted | 37ms | 4328 KiB | ||||
6 | Accepted | 3ms | 3108 KiB | ||||
7 | Accepted | 3ms | 3192 KiB | ||||
subtask3 | 10/10 | ||||||
8 | Accepted | 3ms | 3200 KiB | ||||
9 | Accepted | 3ms | 3200 KiB | ||||
10 | Accepted | 3ms | 3284 KiB | ||||
11 | Accepted | 3ms | 3288 KiB | ||||
12 | Accepted | 3ms | 3236 KiB | ||||
subtask4 | 20/20 | ||||||
13 | Accepted | 3ms | 3488 KiB | ||||
14 | Accepted | 3ms | 3604 KiB | ||||
15 | Accepted | 3ms | 3692 KiB | ||||
16 | Accepted | 3ms | 3648 KiB | ||||
17 | Accepted | 3ms | 3648 KiB | ||||
subtask5 | 25/25 | ||||||
18 | Accepted | 4ms | 3696 KiB | ||||
19 | Accepted | 4ms | 3672 KiB | ||||
20 | Accepted | 4ms | 3904 KiB | ||||
21 | Accepted | 3ms | 4004 KiB | ||||
22 | Accepted | 4ms | 4116 KiB | ||||
subtask6 | 30/30 | ||||||
23 | Accepted | 70ms | 7012 KiB | ||||
24 | Accepted | 48ms | 5600 KiB | ||||
25 | Accepted | 52ms | 5584 KiB | ||||
26 | Accepted | 64ms | 5952 KiB | ||||
27 | Accepted | 67ms | 6388 KiB | ||||
28 | Accepted | 54ms | 5604 KiB | ||||
29 | Accepted | 48ms | 5688 KiB | ||||
30 | Accepted | 37ms | 5680 KiB |