█████████ ████ ███░░░░░███ ░░███ ███ ░░░ ██████ ███████ ██████ ██████ ░███ ███░░███ ███░░███ ███░░███ ███░░███ ░███ ░███ ░███░███ ░███ ░███████ ░███ ░███ ░░███ ███░███ ░███░███ ░███ ░███░░░ ░███ ░███ ░░█████████ ░░██████ ░░████████░░██████ ░░██████ ░░░░░░░░░ ░░░░░░ ░░░░░░░░ ░░░░░░ ░░░░░░

Envío 4772

Problema 0x59 - Substring más larga con máximo K caracteres diferentes

  • Autor: Ikerlb
  • Fecha: 2021-08-13 22:06:19 UTC (Hace más de 2 años)
Caso # Resultado Tiempo Memoria
#1
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 25, in <module>
    print(max_k(s, k))
  File "script.py", line 9, in max_k
    w = Counter()
NameError: name 'Counter' is not defined
0.026 s 3 KBi
#2
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 25, in <module>
    print(max_k(s, k))
  File "script.py", line 9, in max_k
    w = Counter()
NameError: name 'Counter' is not defined
0.02 s 3 KBi
#3
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 25, in <module>
    print(max_k(s, k))
  File "script.py", line 9, in max_k
    w = Counter()
NameError: name 'Counter' is not defined
0.022 s 3 KBi
#4
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 25, in <module>
    print(max_k(s, k))
  File "script.py", line 9, in max_k
    w = Counter()
NameError: name 'Counter' is not defined
0.024 s 3 KBi
#5
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 25, in <module>
    print(max_k(s, k))
  File "script.py", line 9, in max_k
    w = Counter()
NameError: name 'Counter' is not defined
0.02 s 3 KBi
#6
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 25, in <module>
    print(max_k(s, k))
  File "script.py", line 9, in max_k
    w = Counter()
NameError: name 'Counter' is not defined
0.02 s 3 KBi
#7
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 25, in <module>
    print(max_k(s, k))
  File "script.py", line 9, in max_k
    w = Counter()
NameError: name 'Counter' is not defined
0.025 s 3 KBi
#8
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 25, in <module>
    print(max_k(s, k))
  File "script.py", line 9, in max_k
    w = Counter()
NameError: name 'Counter' is not defined
0.025 s 3 KBi
#9
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 25, in <module>
    print(max_k(s, k))
  File "script.py", line 9, in max_k
    w = Counter()
NameError: name 'Counter' is not defined
0.024 s 3 KBi
#10
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 25, in <module>
    print(max_k(s, k))
  File "script.py", line 9, in max_k
    w = Counter()
NameError: name 'Counter' is not defined
0.022 s 3 KBi
#11
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 25, in <module>
    print(max_k(s, k))
  File "script.py", line 9, in max_k
    w = Counter()
NameError: name 'Counter' is not defined
0.024 s 4 KBi
#12
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 25, in <module>
    print(max_k(s, k))
  File "script.py", line 9, in max_k
    w = Counter()
NameError: name 'Counter' is not defined
0.027 s 3 KBi
#13
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 25, in <module>
    print(max_k(s, k))
  File "script.py", line 9, in max_k
    w = Counter()
NameError: name 'Counter' is not defined
0.026 s 3 KBi
#14
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 25, in <module>
    print(max_k(s, k))
  File "script.py", line 9, in max_k
    w = Counter()
NameError: name 'Counter' is not defined
0.023 s 4 KBi
#15
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 25, in <module>
    print(max_k(s, k))
  File "script.py", line 9, in max_k
    w = Counter()
NameError: name 'Counter' is not defined
0.021 s 3 KBi
#16
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 25, in <module>
    print(max_k(s, k))
  File "script.py", line 9, in max_k
    w = Counter()
NameError: name 'Counter' is not defined
0.019 s 3 KBi
#17
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 25, in <module>
    print(max_k(s, k))
  File "script.py", line 9, in max_k
    w = Counter()
NameError: name 'Counter' is not defined
0.02 s 3 KBi
#18
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 25, in <module>
    print(max_k(s, k))
  File "script.py", line 9, in max_k
    w = Counter()
NameError: name 'Counter' is not defined
0.022 s 3 KBi
#19
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 25, in <module>
    print(max_k(s, k))
  File "script.py", line 9, in max_k
    w = Counter()
NameError: name 'Counter' is not defined
0.02 s 3 KBi
#20
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 25, in <module>
    print(max_k(s, k))
  File "script.py", line 9, in max_k
    w = Counter()
NameError: name 'Counter' is not defined
0.026 s 3 KBi
#21
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 25, in <module>
    print(max_k(s, k))
  File "script.py", line 9, in max_k
    w = Counter()
NameError: name 'Counter' is not defined
0.022 s 3 KBi
#22
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 25, in <module>
    print(max_k(s, k))
  File "script.py", line 9, in max_k
    w = Counter()
NameError: name 'Counter' is not defined
0.021 s 3 KBi
#23
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 25, in <module>
    print(max_k(s, k))
  File "script.py", line 9, in max_k
    w = Counter()
NameError: name 'Counter' is not defined
0.029 s 3 KBi
#24
Error en tiempo de ejecución (NZEC)
Exited with error status 1
Traceback (most recent call last):
  File "script.py", line 25, in <module>
    print(max_k(s, k))
  File "script.py", line 9, in max_k
    w = Counter()
NameError: name 'Counter' is not defined
0.029 s 3 KBi
Puntos totales: 0 / 100

Código

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))