Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.005 s | 1 KBi |
#2 |
Correcto
|
0.004 s | 2 KBi |
#3 |
Correcto
|
0.003 s | 2 KBi |
#4 |
Incorrecto
|
0.003 s | 2 KBi |
#5 |
Correcto
|
0.004 s | 63 KBi |
#6 |
Correcto
|
0.005 s | 2 KBi |
#7 |
Correcto
|
0.005 s | 1 KBi |
#8 |
Correcto
|
0.006 s | 2 KBi |
#9 |
Correcto
|
0.007 s | 2 KBi |
#10 |
Incorrecto
|
0.007 s | 2 KBi |
#11 |
Correcto
|
0.016 s | 4 KBi |
#12 |
Correcto
|
0.031 s | 2 KBi |
#13 |
Correcto
|
0.019 s | 3 KBi |
#14 |
Correcto
|
0.118 s | 5 KBi |
#15 |
Correcto
|
0.03 s | 3 KBi |
#16 |
Correcto
|
0.021 s | 2 KBi |
#17 |
Incorrecto
|
0.029 s | 3 KBi |
#18 |
Incorrecto
|
0.029 s | 2 KBi |
#19 |
Incorrecto
|
0.032 s | 2 KBi |
#20 |
Correcto
|
0.025 s | 2 KBi |
#21 |
Incorrecto
|
0.049 s | 2 KBi |
#22 |
Incorrecto
|
0.04 s | 2 KBi |
#23 |
Incorrecto
|
0.05 s | 2 KBi |
#24 |
Incorrecto
|
0.05 s | 2 KBi |
#25 |
Incorrecto
|
0.041 s | 2 KBi |
#26 |
Incorrecto
|
0.061 s | 2 KBi |
#27 |
Incorrecto
|
0.059 s | 2 KBi |
#28 |
Incorrecto
|
0.057 s | 2 KBi |
#29 |
Incorrecto
|
0.064 s | 1 KBi |
#30 |
Incorrecto
|
0.02 s | 2 KBi |
#31 |
Incorrecto
|
0.014 s | 2 KBi |
#32 |
Incorrecto
|
0.027 s | 0 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; while (i < str.length() && j < str.length()) { tabla[str[j]]++; // printf("despues de while.. len: %d size: %d\n", j - i + 1, tabla.size()); // printf("substring => "); // for (int l = i; l <= j; l++) // { // printf("%c", str[l]); // } // printf("\n"); if (j - i + 1 >= k && tabla.size() >= k) { l = i; if (tabla[str[l]] > 1) { while (str[l] == str[l + 1]) { l++; } i = l + 1; } // printf("comparando i: %d , j: %d\n", i, j); 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++; } if (minLen == 100000) { cout << -1; } else { cout << minLen; } return 0; }