4215 | 2023-03-16 17:34:39 | Gabor | Karácsonyi égők | cpp11 | Accepted 100/100 | 71ms | 7212 KiB |
#include <iostream>
#include<bits/stdc++.h>
#include<vector>
using namespace std;
int main()
{
int n,c,i;
cin>>n>>c;
vector<int> egok(n);
vector<int> szinek(c,-1);
for(i=0;i<n;i++)
cin>>egok.at(i);
int hany=0;
bool tele=false;
int kicsi,tavolsag,nagy,kistav;
for(i=0;i<n;i++)
{
if(szinek.at(egok.at(i))==-1)
{
hany++;
szinek.at(egok.at(i))=i;
if(hany==c)
{
kicsi=*min_element(szinek.begin(),szinek.end());
nagy=*max_element(szinek.begin(),szinek.end());
tele=true;
tavolsag=nagy-kicsi+1;
kistav=tavolsag;
}
}
else if(!tele)
szinek.at(egok.at(i))=i;
else if(tele&&szinek.at(egok.at(i))==kicsi)
{
szinek.at(egok.at(i))=i;
kicsi=*min_element(szinek.begin(),szinek.end());
nagy=*max_element(szinek.begin(),szinek.end());
tavolsag=nagy-kicsi+1;
if(tavolsag<kistav)
kistav=tavolsag;
}
else if(tele)
szinek.at(egok.at(i))=i;
}
cout<<tavolsag;
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1812 KiB | ||||
2 | Accepted | 3ms | 2000 KiB | ||||
subtask2 | 15/15 | ||||||
3 | Accepted | 37ms | 3608 KiB | ||||
4 | Accepted | 37ms | 3792 KiB | ||||
5 | Accepted | 37ms | 3756 KiB | ||||
6 | Accepted | 3ms | 2620 KiB | ||||
7 | Accepted | 3ms | 2732 KiB | ||||
subtask3 | 10/10 | ||||||
8 | Accepted | 3ms | 2860 KiB | ||||
9 | Accepted | 3ms | 2980 KiB | ||||
10 | Accepted | 2ms | 3064 KiB | ||||
11 | Accepted | 3ms | 3164 KiB | ||||
12 | Accepted | 3ms | 3248 KiB | ||||
subtask4 | 20/20 | ||||||
13 | Accepted | 3ms | 3252 KiB | ||||
14 | Accepted | 3ms | 3496 KiB | ||||
15 | Accepted | 3ms | 3740 KiB | ||||
16 | Accepted | 3ms | 3984 KiB | ||||
17 | Accepted | 3ms | 4036 KiB | ||||
subtask5 | 25/25 | ||||||
18 | Accepted | 4ms | 4188 KiB | ||||
19 | Accepted | 4ms | 4136 KiB | ||||
20 | Accepted | 4ms | 4228 KiB | ||||
21 | Accepted | 4ms | 4160 KiB | ||||
22 | Accepted | 3ms | 4156 KiB | ||||
subtask6 | 30/30 | ||||||
23 | Accepted | 71ms | 7212 KiB | ||||
24 | Accepted | 48ms | 5816 KiB | ||||
25 | Accepted | 52ms | 5792 KiB | ||||
26 | Accepted | 67ms | 6180 KiB | ||||
27 | Accepted | 68ms | 6728 KiB | ||||
28 | Accepted | 52ms | 5672 KiB | ||||
29 | Accepted | 48ms | 5672 KiB | ||||
30 | Accepted | 37ms | 5804 KiB |