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