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

Envío 2430

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

  • Autor: ppastram
  • Fecha: 2020-12-18 04:35:14 UTC (Hace más de 3 años)
Caso # Resultado Tiempo Memoria
#1
Incorrecto
0.006 s 5 KBi
#2
Incorrecto
0.005 s 1 KBi
#3
Correcto
0.006 s 2 KBi
#4
Incorrecto
0.006 s 10 KBi
#5
Incorrecto
0.005 s 2 KBi
#6
Correcto
0.007 s 2 KBi
#7
Incorrecto
0.004 s 2 KBi
#8
Correcto
0.006 s 2 KBi
#9
Incorrecto
0.008 s 2 KBi
#10
Correcto
0.042 s 2 KBi
#11
Correcto
0.126 s 2 KBi
#12
Correcto
0.06 s 2 KBi
#13
Incorrecto
0.091 s 1 KBi
#14
Correcto
0.047 s 1 KBi
#15
Correcto
0.051 s 2 KBi
#16
Incorrecto
0.08 s 1 KBi
#17
Correcto
0.045 s 1 KBi
#18
Correcto
0.072 s 2 KBi
#19
Error en tiempo de ejecución (NZEC)
Exited with error status 139
run: line 1:     3 Segmentation fault      (core dumped) ./a.out
0.097 s 2 KBi
#20
Correcto
0.052 s 2 KBi
#21
Error en tiempo de ejecución (NZEC)
Exited with error status 139
run: line 1:     3 Segmentation fault      (core dumped) ./a.out
0.071 s 1 KBi
#22
Error en tiempo de ejecución (NZEC)
Exited with error status 139
run: line 1:     3 Segmentation fault      (core dumped) ./a.out
0.087 s 1 KBi
#23
Error en tiempo de ejecución (NZEC)
Exited with error status 139
run: line 1:     3 Segmentation fault      (core dumped) ./a.out
0.089 s 1 KBi
#24
Correcto
0.048 s 5 KBi
Puntos totales: 50 / 100

Código

#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <stack>
#include <algorithm>
#define forn(a, n) for(int a = 0; a<(int) (n); ++a)
#define rforn(a, n) for(int a = (n)-1; a>=0; --a)
using namespace std;
const int N = 6e5+20;

int main()
{
    string s;
    int n;
    cin>>s>>n;
    map <char,int> m;
    int res = 0;

    for(int i = 0, j = 0; i < s.size(); j++)
    {
        m[ s[j] ]++;
        while((int)m.size() > n)
        {
            m[ s[i] ]--;
            if (m[ s[i] ]==0) m.erase(s[i]);
            i++;
        }
        res = max(res, j-i+1);
    }

    cout<<res<<endl;
    return 0;
}