Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.005 s | 2 KBi |
#2 |
Correcto
|
0.004 s | 9 KBi |
#3 |
Correcto
|
0.004 s | 21 KBi |
#4 |
Correcto
|
0.005 s | 24 KBi |
#5 |
Correcto
|
0.004 s | 19 KBi |
#6 |
Correcto
|
0.005 s | 2 KBi |
#7 |
Correcto
|
0.005 s | 61 KBi |
#8 |
Correcto
|
0.004 s | 2 KBi |
#9 |
Correcto
|
0.004 s | 9 KBi |
#10 |
Correcto
|
0.016 s | 1 KBi |
#11 |
Correcto
|
0.123 s | 2 KBi |
#12 |
Correcto
|
0.017 s | 22 KBi |
#13 |
Incorrecto
|
0.096 s | 2 KBi |
#14 |
Correcto
|
0.02 s | 6 KBi |
#15 |
Correcto
|
0.018 s | 55 KBi |
#16 |
Incorrecto
|
0.064 s | 2 KBi |
#17 |
Correcto
|
0.017 s | 2 KBi |
#18 |
Correcto
|
0.069 s | 2 KBi |
#19 |
Correcto
|
0.029 s | 1 KBi |
#20 |
Incorrecto
|
0.106 s | 2 KBi |
#21 |
Incorrecto
|
0.128 s | 9 KBi |
#22 |
Incorrecto
|
0.126 s | 1 KBi |
#23 |
Correcto
|
0.028 s | 2 KBi |
#24 |
Correcto
|
0.018 s | 1 KBi |
#include <bits/stdc++.h> using namespace std; int main() { string str; int maxDif, subStrLen = 0, maxLen = 0, i = 0; map<char, int> tabla; int subStrFirstSequenceChar = str[i]; int subStrFirstSequenceLen = 1; bool firstChar = true; cin >> str; cin >> maxDif; subStrFirstSequenceChar = str[i]; subStrFirstSequenceLen = 1; firstChar = true; while (i < str.length()) { if (firstChar && i + 1 < str.length() && subStrFirstSequenceChar == str[i + 1]) { subStrFirstSequenceLen++; } else { firstChar = false; } tabla[str[i]]; // Se supero el limite de caracteres permitido. Terminamos con esta substring y actualizamos nuestros numeros if (tabla.size() > maxDif) { // printf("se supero barrera en char: '%c'\n", str[i]); if (subStrLen > maxLen) { maxLen = subStrLen; } // Restamos de la tabla el tamano de la primera secuencia de caracteres de la substring que acabamos de analizar // printf("subStrFirstSequenceChar: %c\n", subStrFirstSequenceChar); // printf("subStrFirstSequenceLen: %d\n", subStrFirstSequenceLen); subStrLen -= subStrFirstSequenceLen; // printf("tabla[subStrFirstSequenceChar]: %d\n", tabla[subStrFirstSequenceChar]); tabla[subStrFirstSequenceChar] -= subStrFirstSequenceLen; if (tabla[subStrFirstSequenceChar] <= 0) { // printf("entra a eliminar '%c' de map\n", subStrFirstSequenceChar); tabla.erase(subStrFirstSequenceChar); } subStrFirstSequenceChar = str[i]; subStrFirstSequenceLen = 1; tabla.erase(str[i]); firstChar = true; } else { i++; subStrLen++; } } if (subStrLen > maxLen) { maxLen = subStrLen; } cout << maxLen << endl; }