Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.005 s | 1 KBi |
#2 |
Correcto
|
0.003 s | 1 KBi |
#3 |
Correcto
|
0.005 s | 2 KBi |
#4 |
Correcto
|
0.004 s | 2 KBi |
#5 |
Correcto
|
0.005 s | 1 KBi |
#6 |
Correcto
|
0.005 s | 2 KBi |
#7 |
Correcto
|
0.003 s | 0 KBi |
#8 |
Correcto
|
0.003 s | 2 KBi |
#9 |
Correcto
|
0.004 s | 2 KBi |
#10 |
Correcto
|
0.078 s | 1 KBi |
#11 |
Correcto
|
0.016 s | 1 KBi |
#12 |
Correcto
|
0.089 s | 2 KBi |
#13 |
Correcto
|
0.014 s | 0 KBi |
#14 |
Correcto
|
0.104 s | 2 KBi |
#15 |
Correcto
|
0.121 s | 2 KBi |
#16 |
Correcto
|
0.018 s | 1 KBi |
#17 |
Correcto
|
0.081 s | 5 KBi |
#18 |
Correcto
|
0.062 s | 1 KBi |
#19 |
Correcto
|
0.067 s | 2 KBi |
#20 |
Correcto
|
0.019 s | 5 KBi |
#21 |
Correcto
|
0.098 s | 2 KBi |
#22 |
Correcto
|
0.078 s | 2 KBi |
#23 |
Correcto
|
0.074 s | 2 KBi |
#24 |
Correcto
|
0.072 s | 2 KBi |
#25 |
Correcto
|
0.072 s | 6 KBi |
#26 |
Correcto
|
0.072 s | 2 KBi |
#27 |
Correcto
|
0.053 s | 2 KBi |
#28 |
Correcto
|
0.066 s | 2 KBi |
#29 |
Correcto
|
0.067 s | 3 KBi |
#30 |
Correcto
|
0.021 s | 2 KBi |
#31 |
Correcto
|
0.025 s | 1 KBi |
#32 |
Correcto
|
0.022 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; /* abbbbcccddee 3 */ while (j < str.length()) { while (tabla.size() < k && j < str.length()) { tabla[str[j]]++; j++; } // printf("caracter i: %c -> %d\n", str[i], tabla[str[i]]); while (tabla.size() == k && tabla[str[i]] > 1) { tabla[str[i]]--; i++; // printf("SIZE: %d, caracter i dentro de while: %c -> %d\n", tabla.size(), str[i], tabla[str[i]]); } // printf("substring: "); // for (int z = i; z < j; z++) // { // printf("%c", str[z]); // } // cout << endl; if (tabla.size() >= k) { // printf("SIZE: %d\n", tabla.size()); // cout << "tbala: \n"; // for (auto const &pair : tabla) // { // printf("%c -> %d\n", pair.first, pair.second); // } // cout << "---\n"; minLen = min(minLen, j - i); } while (tabla.size() == k) { tabla[str[i]]--; if (tabla[str[i]] <= 0) { tabla.erase(str[i]); } i++; } tabla[str[j]]++; j++; } // cout << "minlen: " << minLen << endl; cout << ((minLen == 100000) ? -1 : minLen); return 0; }