Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.17 s | 16 KBi |
#2 |
Correcto
|
0.155 s | 16 KBi |
#3 |
Correcto
|
0.159 s | 16 KBi |
#4 |
Correcto
|
0.17 s | 15 KBi |
#5 |
Correcto
|
0.165 s | 16 KBi |
#6 |
Correcto
|
0.178 s | 16 KBi |
#7 |
Correcto
|
0.15 s | 15 KBi |
#8 |
Correcto
|
0.167 s | 15 KBi |
#9 |
Correcto
|
0.158 s | 15 KBi |
#10 |
Correcto
|
0.401 s | 23 KBi |
#11 |
Correcto
|
0.422 s | 24 KBi |
#12 |
Correcto
|
0.341 s | 21 KBi |
#13 |
Correcto
|
0.485 s | 25 KBi |
#14 |
Correcto
|
0.399 s | 24 KBi |
#15 |
Correcto
|
0.366 s | 22 KBi |
#16 |
Correcto
|
0.459 s | 22 KBi |
#17 |
Correcto
|
0.416 s | 22 KBi |
#18 |
Correcto
|
0.453 s | 22 KBi |
#19 |
Correcto
|
0.405 s | 22 KBi |
#20 |
Correcto
|
0.415 s | 25 KBi |
#21 |
Correcto
|
0.414 s | 25 KBi |
#22 |
Correcto
|
0.449 s | 26 KBi |
#23 |
Correcto
|
0.375 s | 23 KBi |
#24 |
Correcto
|
0.368 s | 23 KBi |
import java.io.IOException; import java.util.HashMap; import java.util.Map; import java.util.Scanner; public class Main{ public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); String s = sc.next(); int k = sc.nextInt(); sc.close(); Map<Character, Integer> m = new HashMap<Character, Integer>(); int current = 0; Character c; Integer in, max = 0; for (int i = 0; i < s.length(); i++) { c = s.charAt(i); in = m.get(c); if (in != null) { m.put(c, m.get(c) + 1); } else { m.put(c, 1); } while (m.size() > k) { c = s.charAt(current++); in = m.get(c); if (in != null) { m.put(c, in - 1); if (m.get(c) == 0) { m.remove(c); } } } max = Math.max(max, 1 + i - current); } System.out.println(max); } }