10630 | 2024-04-07 00:23:09 | 111 | Karácsonyi égők | cpp17 | Accepted 100/100 | 30ms | 13492 KiB |
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N,M;
cin>>N>>M;
int ans=N;
vector<int>v(M,-1);
int c=0;
deque<pair<int,int>>q;
for(int i=0;i<N;i++){
int x;
cin>>x;
if(v[x]==-1){
c++;
}
v[x]=i;
q.emplace_back(x,i);
while(v[q.front().first]>q.front().second){
q.pop_front();
}
if(c==M){
ans=min(ans,q.back().second-q.front().second+1);
}
}
cout<<ans<<'\n';
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1828 KiB | ||||
2 | Accepted | 3ms | 2020 KiB | ||||
subtask2 | 15/15 | ||||||
3 | Accepted | 19ms | 5812 KiB | ||||
4 | Accepted | 19ms | 5992 KiB | ||||
5 | Accepted | 19ms | 5800 KiB | ||||
6 | Accepted | 3ms | 2732 KiB | ||||
7 | Accepted | 3ms | 2868 KiB | ||||
subtask3 | 10/10 | ||||||
8 | Accepted | 2ms | 2740 KiB | ||||
9 | Accepted | 3ms | 2868 KiB | ||||
10 | Accepted | 2ms | 2952 KiB | ||||
11 | Accepted | 2ms | 2952 KiB | ||||
12 | Accepted | 3ms | 2980 KiB | ||||
subtask4 | 20/20 | ||||||
13 | Accepted | 3ms | 3060 KiB | ||||
14 | Accepted | 3ms | 3064 KiB | ||||
15 | Accepted | 3ms | 3068 KiB | ||||
16 | Accepted | 3ms | 3168 KiB | ||||
17 | Accepted | 3ms | 3160 KiB | ||||
subtask5 | 25/25 | ||||||
18 | Accepted | 3ms | 3540 KiB | ||||
19 | Accepted | 3ms | 3600 KiB | ||||
20 | Accepted | 3ms | 3560 KiB | ||||
21 | Accepted | 3ms | 3544 KiB | ||||
22 | Accepted | 3ms | 3908 KiB | ||||
subtask6 | 30/30 | ||||||
23 | Accepted | 30ms | 13492 KiB | ||||
24 | Accepted | 23ms | 9996 KiB | ||||
25 | Accepted | 26ms | 10292 KiB | ||||
26 | Accepted | 28ms | 10780 KiB | ||||
27 | Accepted | 28ms | 12472 KiB | ||||
28 | Accepted | 27ms | 10372 KiB | ||||
29 | Accepted | 21ms | 6148 KiB | ||||
30 | Accepted | 19ms | 9160 KiB |