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

Envío 2296

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

  • Autor: juantamayo26
  • Fecha: 2020-12-12 00:52:31 UTC (Hace más de 3 años)
Caso # Resultado Tiempo Memoria
#1
Correcto
0.004 s 2 KBi
#2
Correcto
0.005 s 2 KBi
#3
Correcto
0.007 s 1 KBi
#4
Correcto
0.006 s 1 KBi
#5
Correcto
0.005 s 2 KBi
#6
Correcto
0.005 s 1 KBi
#7
Correcto
0.005 s 2 KBi
#8
Correcto
0.005 s 2 KBi
#9
Correcto
0.006 s 1 KBi
#10
Tiempo límite excedido
1.077 s 1 KBi
#11
Correcto
0.067 s 2 KBi
#12
Tiempo límite excedido
1.062 s 2 KBi
#13
Correcto
0.129 s 1 KBi
#14
Tiempo límite excedido
1.062 s 1 KBi
#15
Tiempo límite excedido
1.084 s 2 KBi
#16
Correcto
0.126 s 2 KBi
#17
Tiempo límite excedido
1.068 s 2 KBi
#18
Correcto
0.096 s 2 KBi
#19
Tiempo límite excedido
1.045 s 1 KBi
#20
Tiempo límite excedido
1.059 s 2 KBi
#21
Tiempo límite excedido
1.007 s 2 KBi
#22
Tiempo límite excedido
1.028 s 2 KBi
#23
Tiempo límite excedido
1.027 s 1 KBi
#24
Tiempo límite excedido
1.036 s 2 KBi
Puntos totales: 55 / 100

Código

#include <bits/stdc++.h>

using namespace std;

#define endl '\n'
#define ll long long
#define pii pair<int, int>
const int maxi = 1e9;

int main(){
  ios::sync_with_stdio(0); cin.tie(0); 
  string s;
  cin>>s;
  int n;
  cin>>n;
  int ans = 1, i=0, j=1;
  set <char> aux;
//  while(j<s.size()){
//    aux.insert(s[i]);
//    if(aux.size()<=n){
//      aux.insert(s[j]);
//      ans = max(ans, j-i+1);
//      j++;
//    }else{
//      i++;
//      j=i+1;
//      aux.clear();
//    }
//  }
  for(int i=0;i<s.size(); i++){
    int j=i+1;
    aux.insert(s[i]);
    while(j<s.size()){
      aux.insert(s[j]);
      if(aux.size()<=n){
        ans = max(ans, j-i+1);
        j++;
      }else{
        break;
      }
    }
    aux.clear();
  }
  cout<<ans<<endl;
  
  return 0;
}