Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.026 s | 3 KBi |
#2 |
Correcto
|
0.019 s | 3 KBi |
#3 |
Correcto
|
0.022 s | 3 KBi |
#4 |
Correcto
|
0.024 s | 3 KBi |
#5 |
Correcto
|
0.027 s | 3 KBi |
#6 |
Correcto
|
0.026 s | 3 KBi |
#7 |
Correcto
|
0.029 s | 3 KBi |
#8 |
Correcto
|
0.026 s | 3 KBi |
#9 |
Correcto
|
0.021 s | 3 KBi |
#10 |
Correcto
|
0.156 s | 3 KBi |
#11 |
Correcto
|
0.055 s | 3 KBi |
#12 |
Correcto
|
0.123 s | 3 KBi |
#13 |
Correcto
|
0.059 s | 3 KBi |
#14 |
Correcto
|
0.126 s | 3 KBi |
#15 |
Correcto
|
0.118 s | 3 KBi |
#16 |
Correcto
|
0.061 s | 3 KBi |
#17 |
Correcto
|
0.189 s | 3 KBi |
#18 |
Correcto
|
0.128 s | 3 KBi |
#19 |
Correcto
|
0.172 s | 3 KBi |
#20 |
Correcto
|
0.061 s | 3 KBi |
#21 |
Correcto
|
0.138 s | 3 KBi |
#22 |
Correcto
|
0.125 s | 3 KBi |
#23 |
Correcto
|
0.121 s | 3 KBi |
#24 |
Correcto
|
0.157 s | 3 KBi |
#25 |
Correcto
|
0.166 s | 3 KBi |
#26 |
Correcto
|
0.114 s | 3 KBi |
#27 |
Correcto
|
0.127 s | 3 KBi |
#28 |
Correcto
|
0.135 s | 3 KBi |
#29 |
Correcto
|
0.126 s | 3 KBi |
#30 |
Correcto
|
0.056 s | 3 KBi |
#31 |
Correcto
|
0.102 s | 3 KBi |
#32 |
Correcto
|
0.084 s | 3 KBi |
import math def min_substr(s, k): i = 0 n = len(s) curr_min = float("inf") letters = dict() for j in range(n): l = s[j] cl = letters.get(l, 0) letters[l] = cl + 1 while len(letters) >= k: curr_min = min(curr_min, j - i + 1) l = s[i] cl = letters[l] letters[l] = cl - 1 if letters[l] == 0: del letters[l] i = i + 1 return -1 if math.isinf(curr_min) else curr_min s = input() k = int(input()) print(min_substr(s, k))