Skip to main content

aizu_online_judge/dsl/
dsl_3_b.rs

1use competitive::prelude::*;
2
3#[verify::aizu_online_judge("DSL_3_B")]
4pub fn dsl_3_b(reader: impl Read, writer: impl Write) {
5    prepare_io!(reader, writer);
6    sc!(n, k, a: [Usize1; n]);
7    let mut counter = vec![0; 100_001];
8    let mut j = 0;
9    let mut ans = usize::MAX;
10    let mut cnt = 0;
11    for i in 0..n {
12        while j < n && cnt < k {
13            cnt += (a[j] < k && counter[a[j]] == 0) as usize;
14            counter[a[j]] += 1;
15            j += 1;
16        }
17        if cnt == k {
18            ans = ans.min(j - i);
19        }
20        counter[a[i]] -= 1;
21        cnt -= (a[i] < k && counter[a[i]] == 0) as usize;
22    }
23    pp!(if ans == usize::MAX { 0 } else { ans });
24}