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

Envío 3945

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

  • Autor: bryancalisto
  • Fecha: 2021-04-24 14:16:31 UTC (Hace casi 3 años)
Caso # Resultado Tiempo Memoria
#1
Correcto
0.004 s 1 KBi
#2
Correcto
0.005 s 1 KBi
#3
Correcto
0.004 s 1 KBi
#4
Correcto
0.005 s 1 KBi
#5
Correcto
0.005 s 1 KBi
#6
Correcto
0.005 s 2 KBi
#7
Correcto
0.004 s 1 KBi
#8
Correcto
0.006 s 1 KBi
#9
Correcto
0.004 s 2 KBi
#10
Tiempo límite excedido
1.049 s 1 KBi
#11
Correcto
0.079 s 2 KBi
#12
Tiempo límite excedido
1.066 s 2 KBi
#13
Correcto
0.121 s 2 KBi
#14
Tiempo límite excedido
1.008 s 1 KBi
#15
Tiempo límite excedido
1.046 s 2 KBi
#16
Correcto
0.175 s 2 KBi
#17
Tiempo límite excedido
1.089 s 1 KBi
#18
Correcto
0.085 s 2 KBi
#19
Tiempo límite excedido
1.066 s 1 KBi
#20
Tiempo límite excedido
1.089 s 2 KBi
#21
Tiempo límite excedido
1.04 s 1 KBi
#22
Tiempo límite excedido
1.062 s 1 KBi
#23
Tiempo límite excedido
1.039 s 1 KBi
#24
Tiempo límite excedido
1.058 s 1 KBi
Puntos totales: 55 / 100

Código

#include <bits/stdc++.h>

using namespace std;

int main()
{
  string str;
  int maxDif, subStrLen, maxLen = 0, i = 0, subStrIndex;
  map<char, int> tabla;

  cin >> str;
  cin >> maxDif;

  while (i < str.length())
  {
    subStrLen = 0;
    subStrIndex = i;

    while (subStrIndex < str.length())
    {
      tabla[str[subStrIndex]];

      if (tabla.size() > maxDif)
      {
        break;
      }

      subStrLen++;
      subStrIndex++;
    }

    if (subStrLen > maxLen)
    {
      maxLen = subStrLen;
    }

    tabla.clear();
    i++;
  }

  cout << maxLen << endl;

  return 0;
}