Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.027 s | 3 KBi |
#2 |
Correcto
|
0.021 s | 3 KBi |
#3 |
Correcto
|
0.023 s | 3 KBi |
#4 |
Correcto
|
0.027 s | 3 KBi |
#5 |
Correcto
|
0.037 s | 3 KBi |
#6 |
Correcto
|
0.024 s | 3 KBi |
#7 |
Correcto
|
0.029 s | 3 KBi |
#8 |
Correcto
|
0.025 s | 3 KBi |
#9 |
Correcto
|
0.026 s | 3 KBi |
#10 |
Correcto
|
0.13 s | 3 KBi |
#11 |
Correcto
|
0.245 s | 3 KBi |
#12 |
Correcto
|
0.127 s | 3 KBi |
#13 |
Correcto
|
0.238 s | 3 KBi |
#14 |
Correcto
|
0.133 s | 3 KBi |
#15 |
Correcto
|
0.12 s | 3 KBi |
#16 |
Correcto
|
0.221 s | 3 KBi |
#17 |
Correcto
|
0.13 s | 3 KBi |
#18 |
Correcto
|
0.23 s | 4 KBi |
#19 |
Correcto
|
0.136 s | 3 KBi |
#20 |
Correcto
|
0.204 s | 3 KBi |
#21 |
Correcto
|
0.223 s | 3 KBi |
#22 |
Correcto
|
0.217 s | 3 KBi |
#23 |
Correcto
|
0.133 s | 3 KBi |
#24 |
Correcto
|
0.168 s | 3 KBi |
from collections import Counter def decrement_and_delete(cnt, c): if cnt[c] == 1: del cnt[c] else: cnt[c] -= 1 def max_k(s, k): l = r = 0 w = Counter() res = 0 while r < len(s): while l <= len(s) and len(w) > k: decrement_and_delete(w, s[l]) l += 1 res = max(res, r - l) w[s[r]] += 1 r += 1 if len(w) <= k: res = max(res, r - l) return res if __name__ == "__main__": s = input() k = int(input()) print(max_k(s, k))