Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.003 s | 1 KBi |
#2 |
Correcto
|
0.003 s | 10 KBi |
#3 |
Correcto
|
0.003 s | 2 KBi |
#4 |
Correcto
|
0.007 s | 2 KBi |
#5 |
Correcto
|
0.005 s | 2 KBi |
#6 |
Correcto
|
0.005 s | 2 KBi |
#7 |
Correcto
|
0.004 s | 1 KBi |
#8 |
Correcto
|
0.004 s | 2 KBi |
#9 |
Correcto
|
0.003 s | 11 KBi |
#10 |
Correcto
|
0.006 s | 1 KBi |
#11 |
Correcto
|
0.016 s | 2 KBi |
#12 |
Correcto
|
0.034 s | 0 KBi |
#13 |
Correcto
|
0.018 s | 1 KBi |
#14 |
Correcto
|
0.103 s | 2 KBi |
#15 |
Correcto
|
0.054 s | 2 KBi |
#16 |
Correcto
|
0.019 s | 1 KBi |
#17 |
Correcto
|
0.005 s | 0 KBi |
#18 |
Correcto
|
0.061 s | 1 KBi |
#19 |
Correcto
|
0.086 s | 0 KBi |
#20 |
Correcto
|
0.028 s | 2 KBi |
#21 |
Incorrecto
|
0.108 s | 2 KBi |
#22 |
Incorrecto
|
0.082 s | 2 KBi |
#23 |
Incorrecto
|
0.089 s | 2 KBi |
#24 |
Incorrecto
|
0.093 s | 2 KBi |
#25 |
Incorrecto
|
0.083 s | 2 KBi |
#26 |
Incorrecto
|
0.069 s | 1 KBi |
#27 |
Incorrecto
|
0.118 s | 2 KBi |
#28 |
Incorrecto
|
0.083 s | 2 KBi |
#29 |
Incorrecto
|
0.095 s | 2 KBi |
#30 |
Incorrecto
|
0.021 s | 1 KBi |
#31 |
Correcto
|
0.035 s | 2 KBi |
#32 |
Correcto
|
0.023 s | 2 KBi |
#include <bits/stdc++.h> using namespace std; int main() { string str; int k, i = 0, j = 0, l = 0, minLen = 100000, len; map<char, int> tabla; cin >> str; cin >> k; if (k == 1) { cout << 1; return 0; } while (i < str.length() && j < str.length()) { tabla[str[j]]++; // printf("despues de while.. len: %d size: %d\n", j - i + 1, tabla.size()); if (j - i + 1 >= k && tabla.size() >= k) { l = i; // printf("tabla[%c]: %d str[l] == str[l + 1] ... %c == %c\n", str[l], tabla[str[l]], str[l], str[l + 1]); if (tabla[str[l]] > 1 && str[l] != str[l + 1]) { tabla[str[l]]--; i++; } else if (tabla[str[l]] > 1) { while (tabla[str[l]] > 1) { tabla[str[l]]--; i++; } } // DEBUG // printf("substring => "); // for (int m = i; m <= j; m++) // { // printf("%c", str[m]); // } // printf("\n"); minLen = min(minLen, j - i + 1); } while (tabla.size() >= k && j - i + 1 > k) { tabla[str[i]]--; if (tabla[str[i]] == 0) { tabla.erase(str[i]); } i++; } j++; } cout << ((minLen == 100000) ? -1 : minLen); return 0; }