4198 | 2023-03-16 06:47:39 | Ancsa | Karácsonyi égők | cpp11 | Accepted 100/100 | 92ms | 6912 KiB |
#include <bits/stdc++.h>
#include <vector>
using namespace std;
/*
be:
10 4
0 1 3 0 0 1 2 0 2 3
ki: 5
be:
11 3
1 1 0 0 2 2 1 1 1 2 2
ki: 4
*/
int main()
{
int n,c;
cin>>n>>c;
vector<int> indexek(c,-1), rendezett(c);
int uj,index=0, kicsi, nagy, tav, hany=0;
bool tele=false;
for(int i=0;i<n;i++)
{
cin>>uj;
if (indexek.at(uj)==-1)
{
hany++;
indexek.at(uj)=index;
index++;
if (hany==c)
{
rendezett=indexek;
sort(rendezett.begin(), rendezett.end());
nagy=rendezett.at(c-1);
kicsi=rendezett.at(0);
tav=nagy-kicsi+1;
//cout<<index<<" "<<tav<<endl;
tele=true;
}
}
else if (! tele)
{
indexek.at(uj)=index;
index++;
}
else
{
if (indexek.at(uj)==kicsi)
{
indexek.at(uj)=index;
index++;
rendezett=indexek;
sort(rendezett.begin(),rendezett.end());
kicsi=rendezett.at(0);
nagy=rendezett.at(c-1);
int ujtav=nagy-kicsi+1;
if (ujtav<=tav)
{
tav=ujtav;
//cout<<index<<" "<<tav<<endl;
}
}
else
{
indexek.at(uj)=index;
index++;
nagy++;
}
}
}
cout << tav ;
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1812 KiB | ||||
2 | Accepted | 3ms | 2056 KiB | ||||
subtask2 | 15/15 | ||||||
3 | Accepted | 37ms | 2268 KiB | ||||
4 | Accepted | 37ms | 2480 KiB | ||||
5 | Accepted | 37ms | 2560 KiB | ||||
6 | Accepted | 3ms | 2760 KiB | ||||
7 | Accepted | 3ms | 2972 KiB | ||||
subtask3 | 10/10 | ||||||
8 | Accepted | 3ms | 3116 KiB | ||||
9 | Accepted | 3ms | 3200 KiB | ||||
10 | Accepted | 2ms | 3172 KiB | ||||
11 | Accepted | 3ms | 3288 KiB | ||||
12 | Accepted | 3ms | 3532 KiB | ||||
subtask4 | 20/20 | ||||||
13 | Accepted | 3ms | 3612 KiB | ||||
14 | Accepted | 3ms | 3704 KiB | ||||
15 | Accepted | 3ms | 3836 KiB | ||||
16 | Accepted | 3ms | 3880 KiB | ||||
17 | Accepted | 3ms | 4008 KiB | ||||
subtask5 | 25/25 | ||||||
18 | Accepted | 4ms | 4040 KiB | ||||
19 | Accepted | 4ms | 3884 KiB | ||||
20 | Accepted | 4ms | 4008 KiB | ||||
21 | Accepted | 4ms | 4004 KiB | ||||
22 | Accepted | 3ms | 4000 KiB | ||||
subtask6 | 30/30 | ||||||
23 | Accepted | 92ms | 6912 KiB | ||||
24 | Accepted | 48ms | 4076 KiB | ||||
25 | Accepted | 52ms | 4124 KiB | ||||
26 | Accepted | 71ms | 4832 KiB | ||||
27 | Accepted | 79ms | 5568 KiB | ||||
28 | Accepted | 52ms | 4224 KiB | ||||
29 | Accepted | 48ms | 4112 KiB | ||||
30 | Accepted | 37ms | 4228 KiB |