4223 | 2023-03-16 17:42:46 | Markopolo | Karácsonyi égők | cpp11 | Accepted 100/100 | 71ms | 7612 KiB |
#include<bits/stdc++.h>
using namespace std;
/*
10 4
0 1 3 0 0 1 2 0 2 3
*/
int main()
{
int n,c,i,sz,h=0,kicsi,nagy,tav,kt; // h a szin vektor kitoltott elemeinek szama
cin>>n>>c;
vector<int> szin(c,-1); // ez az indextabla
vector<int> ego(n);
for(i=0;i<n;i++)
cin>>ego.at(i);
bool t=false;
for(i=0;i<n;i++)
{
sz=ego.at(i);
if(szin.at(sz)==-1)
{
h++;
szin.at(sz)=i;
if(h==c) // amiko tele van sz index
{
kicsi=*min_element(szin.begin(),szin.end());
nagy=*max_element(szin.begin(),szin.end());
t=true;
tav=nagy-kicsi+1;
kt=t;
}
}
else if(!t)
szin.at(sz)=i;
else if(t && szin.at(sz)==kicsi)
{
szin.at(sz)=i;
kicsi=*min_element(szin.begin(),szin.end());
nagy=*max_element(szin.begin(),szin.end());
tav=nagy-kicsi+1;
if(tav<kt)
kt=tav;
}
else if(t)
{
szin.at(sz)=i;
}
}
cout<<tav;
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1808 KiB | ||||
2 | Accepted | 3ms | 2000 KiB | ||||
subtask2 | 15/15 | ||||||
3 | Accepted | 37ms | 3436 KiB | ||||
4 | Accepted | 37ms | 3568 KiB | ||||
5 | Accepted | 37ms | 3788 KiB | ||||
6 | Accepted | 3ms | 2652 KiB | ||||
7 | Accepted | 3ms | 2872 KiB | ||||
subtask3 | 10/10 | ||||||
8 | Accepted | 3ms | 2988 KiB | ||||
9 | Accepted | 3ms | 3164 KiB | ||||
10 | Accepted | 3ms | 3368 KiB | ||||
11 | Accepted | 3ms | 3456 KiB | ||||
12 | Accepted | 3ms | 3592 KiB | ||||
subtask4 | 20/20 | ||||||
13 | Accepted | 3ms | 3740 KiB | ||||
14 | Accepted | 3ms | 3848 KiB | ||||
15 | Accepted | 3ms | 3716 KiB | ||||
16 | Accepted | 3ms | 3972 KiB | ||||
17 | Accepted | 3ms | 4048 KiB | ||||
subtask5 | 25/25 | ||||||
18 | Accepted | 4ms | 4352 KiB | ||||
19 | Accepted | 4ms | 4360 KiB | ||||
20 | Accepted | 4ms | 4444 KiB | ||||
21 | Accepted | 4ms | 4364 KiB | ||||
22 | Accepted | 3ms | 4364 KiB | ||||
subtask6 | 30/30 | ||||||
23 | Accepted | 71ms | 7612 KiB | ||||
24 | Accepted | 48ms | 6008 KiB | ||||
25 | Accepted | 56ms | 5988 KiB | ||||
26 | Accepted | 65ms | 6152 KiB | ||||
27 | Accepted | 68ms | 6732 KiB | ||||
28 | Accepted | 54ms | 6020 KiB | ||||
29 | Accepted | 50ms | 6104 KiB | ||||
30 | Accepted | 37ms | 6188 KiB |