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

Envío 2294

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

  • Autor: juantamayo26
  • Fecha: 2020-12-12 00:41:09 UTC (Hace más de 3 años)
Caso # Resultado Tiempo Memoria
#1
Correcto
0.005 s 2 KBi
#2
Correcto
0.007 s 21 KBi
#3
Correcto
0.006 s 2 KBi
#4
Correcto
0.004 s 2 KBi
#5
Correcto
0.006 s 1 KBi
#6
Incorrecto
0.006 s 8 KBi
#7
Incorrecto
0.005 s 1 KBi
#8
Incorrecto
0.005 s 2 KBi
#9
Correcto
0.005 s 2 KBi
#10
Tiempo límite excedido
1.039 s 2 KBi
#11
Incorrecto
0.064 s 2 KBi
#12
Tiempo límite excedido
1.007 s 2 KBi
#13
Correcto
0.097 s 2 KBi
#14
Tiempo límite excedido
1.07 s 2 KBi
#15
Tiempo límite excedido
1.056 s 18 KBi
#16
Correcto
0.128 s 23 KBi
#17
Tiempo límite excedido
1.066 s 2 KBi
#18
Correcto
0.076 s 2 KBi
#19
Tiempo límite excedido
1.043 s 2 KBi
#20
Tiempo límite excedido
1.022 s 19 KBi
#21
Tiempo límite excedido
1.032 s 19 KBi
#22
Tiempo límite excedido
1.027 s 2 KBi
#23
Tiempo límite excedido
1.04 s 17 KBi
#24
Tiempo límite excedido
1.022 s 22 KBi
Puntos totales: 38 / 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 = 0;
  set <char> aux;
  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;
}