Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.022 s | 3 KBi |
#2 |
Correcto
|
0.022 s | 3 KBi |
#3 |
Correcto
|
0.021 s | 3 KBi |
#4 |
Correcto
|
0.035 s | 4 KBi |
#5 |
Correcto
|
0.02 s | 3 KBi |
#6 |
Correcto
|
0.023 s | 3 KBi |
#7 |
Correcto
|
0.017 s | 3 KBi |
#8 |
Correcto
|
0.022 s | 3 KBi |
#9 |
Correcto
|
0.042 s | 7 KBi |
#10 |
Correcto
|
0.023 s | 3 KBi |
#11 |
Correcto
|
0.106 s | 3 KBi |
#12 |
Correcto
|
0.137 s | 3 KBi |
#13 |
Correcto
|
0.113 s | 3 KBi |
#14 |
Correcto
|
0.139 s | 3 KBi |
#15 |
Correcto
|
0.145 s | 3 KBi |
#16 |
Correcto
|
0.114 s | 3 KBi |
#17 |
Correcto
|
0.022 s | 3 KBi |
#18 |
Correcto
|
0.147 s | 5 KBi |
#19 |
Correcto
|
0.201 s | 3 KBi |
#20 |
Correcto
|
0.143 s | 7 KBi |
#21 |
Correcto
|
0.209 s | 3 KBi |
#22 |
Correcto
|
0.136 s | 3 KBi |
#23 |
Correcto
|
0.229 s | 3 KBi |
#24 |
Correcto
|
0.131 s | 3 KBi |
#25 |
Correcto
|
0.2 s | 4 KBi |
#26 |
Correcto
|
0.149 s | 3 KBi |
#27 |
Correcto
|
0.227 s | 3 KBi |
#28 |
Correcto
|
0.16 s | 4 KBi |
#29 |
Correcto
|
0.138 s | 3 KBi |
#30 |
Correcto
|
0.105 s | 3 KBi |
#31 |
Correcto
|
0.107 s | 3 KBi |
#32 |
Correcto
|
0.127 s | 3 KBi |
import math def find_min_substring(arr, k): if k == 1: return 1 i, j = 0, 0 chars = {} answer = math.inf length = len(arr) while i < length: while len(chars) < k and j < length: chars[arr[j]] = chars.get(arr[j], 0) + 1 j += 1 if len(chars) >= k: answer = min(answer, j - i) chars[arr[i]] -= 1 if chars[arr[i]] == 0: del chars[arr[i]] i += 1 return answer s = input() k = int(input()) min_substring = find_min_substring(s, k) print(-1 if min_substring == math.inf else min_substring)