Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.026 s | 3 KBi |
#2 |
Correcto
|
0.024 s | 3 KBi |
#3 |
Correcto
|
0.028 s | 3 KBi |
#4 |
Correcto
|
0.024 s | 3 KBi |
#5 |
Correcto
|
0.023 s | 3 KBi |
#6 |
Correcto
|
0.024 s | 3 KBi |
#7 |
Correcto
|
0.035 s | 3 KBi |
#8 |
Correcto
|
0.023 s | 3 KBi |
#9 |
Correcto
|
0.026 s | 3 KBi |
#10 |
Correcto
|
0.231 s | 3 KBi |
#11 |
Correcto
|
0.109 s | 3 KBi |
#12 |
Correcto
|
0.27 s | 3 KBi |
#13 |
Correcto
|
0.101 s | 3 KBi |
#14 |
Correcto
|
0.259 s | 3 KBi |
#15 |
Correcto
|
0.259 s | 3 KBi |
#16 |
Correcto
|
0.11 s | 3 KBi |
#17 |
Correcto
|
0.249 s | 3 KBi |
#18 |
Correcto
|
0.236 s | 3 KBi |
#19 |
Correcto
|
0.262 s | 3 KBi |
#20 |
Correcto
|
0.097 s | 3 KBi |
#21 |
Correcto
|
0.217 s | 3 KBi |
#22 |
Correcto
|
0.225 s | 3 KBi |
#23 |
Correcto
|
0.209 s | 3 KBi |
#24 |
Correcto
|
0.237 s | 3 KBi |
#25 |
Correcto
|
0.242 s | 3 KBi |
#26 |
Correcto
|
0.231 s | 3 KBi |
#27 |
Correcto
|
0.228 s | 3 KBi |
#28 |
Correcto
|
0.225 s | 3 KBi |
#29 |
Correcto
|
0.263 s | 3 KBi |
#30 |
Correcto
|
0.099 s | 3 KBi |
#31 |
Correcto
|
0.159 s | 3 KBi |
#32 |
Correcto
|
0.167 s | 3 KBi |
from collections import Counter import math def decrement_and_delete(cnt, c): if cnt[c] == 1: del cnt[c] else: cnt[c] -= 1 def min_k(s, k): l, r = 0, 0 w = Counter() res = math.inf while r < len(s): w[s[r]] += 1 if len(w) == k: res = min(res, r - l + 1) while l < r and len(w) >= k: decrement_and_delete(w, s[l]) l += 1 if len(w) == k: res = min(res, r - l + 1) r += 1 return res if res != math.inf else -1 if __name__ == "__main__": s = input() k = int(input()) print(min_k(s, k))