Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.006 s | 1 KBi |
#2 |
Correcto
|
0.005 s | 1 KBi |
#3 |
Correcto
|
0.005 s | 2 KBi |
#4 |
Correcto
|
0.005 s | 2 KBi |
#5 |
Correcto
|
0.005 s | 1 KBi |
#6 |
Correcto
|
0.005 s | 1 KBi |
#7 |
Correcto
|
0.005 s | 2 KBi |
#8 |
Correcto
|
0.004 s | 1 KBi |
#9 |
Correcto
|
0.004 s | 2 KBi |
#10 |
Correcto
|
0.022 s | 2 KBi |
#11 |
Correcto
|
0.095 s | 2 KBi |
#12 |
Correcto
|
0.022 s | 2 KBi |
#13 |
Correcto
|
0.096 s | 2 KBi |
#14 |
Correcto
|
0.028 s | 2 KBi |
#15 |
Correcto
|
0.022 s | 2 KBi |
#16 |
Correcto
|
0.074 s | 2 KBi |
#17 |
Correcto
|
0.018 s | 2 KBi |
#18 |
Correcto
|
0.086 s | 2 KBi |
#19 |
Correcto
|
0.03 s | 2 KBi |
#20 |
Correcto
|
0.053 s | 2 KBi |
#21 |
Correcto
|
0.058 s | 2 KBi |
#22 |
Correcto
|
0.056 s | 2 KBi |
#23 |
Correcto
|
0.03 s | 2 KBi |
#24 |
Correcto
|
0.026 s | 2 KBi |
#include <iostream> #include <map> // #include <bits/stdc++.h> using namespace std; int main() { string word; int k; cin >> word >> k; map<int, int> map_count; int left = 0; int longest = 0; for (int right = 0; right < word.size(); right++) { char letter = word[right]; map_count[letter]++; while (map_count.size() > k) { char left_char = word[left]; map_count[left_char]--; if (map_count[left_char] == 0) { map_count.erase(left_char); } left++; } longest = max(longest, right - left + 1); } cout << longest << endl; }