4219 | 2023-03-16 17:39:19 | Alex | Karácsonyi égők | cpp11 | Accepted 100/100 | 70ms | 6912 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 | 1812 KiB | ||||
2 | Accepted | 3ms | 2060 KiB | ||||
subtask2 | 15/15 | ||||||
3 | Accepted | 37ms | 3788 KiB | ||||
4 | Accepted | 37ms | 4088 KiB | ||||
5 | Accepted | 37ms | 3992 KiB | ||||
6 | Accepted | 3ms | 3008 KiB | ||||
7 | Accepted | 3ms | 2996 KiB | ||||
subtask3 | 10/10 | ||||||
8 | Accepted | 3ms | 3228 KiB | ||||
9 | Accepted | 2ms | 3276 KiB | ||||
10 | Accepted | 3ms | 3344 KiB | ||||
11 | Accepted | 3ms | 3484 KiB | ||||
12 | Accepted | 2ms | 3548 KiB | ||||
subtask4 | 20/20 | ||||||
13 | Accepted | 3ms | 3444 KiB | ||||
14 | Accepted | 3ms | 3332 KiB | ||||
15 | Accepted | 3ms | 3328 KiB | ||||
16 | Accepted | 3ms | 3452 KiB | ||||
17 | Accepted | 3ms | 3572 KiB | ||||
subtask5 | 25/25 | ||||||
18 | Accepted | 4ms | 3736 KiB | ||||
19 | Accepted | 4ms | 3840 KiB | ||||
20 | Accepted | 4ms | 3928 KiB | ||||
21 | Accepted | 3ms | 3916 KiB | ||||
22 | Accepted | 3ms | 4048 KiB | ||||
subtask6 | 30/30 | ||||||
23 | Accepted | 70ms | 6912 KiB | ||||
24 | Accepted | 50ms | 5240 KiB | ||||
25 | Accepted | 54ms | 5320 KiB | ||||
26 | Accepted | 64ms | 5712 KiB | ||||
27 | Accepted | 67ms | 6260 KiB | ||||
28 | Accepted | 54ms | 5680 KiB | ||||
29 | Accepted | 48ms | 5668 KiB | ||||
30 | Accepted | 37ms | 5744 KiB |