Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.006 s | 11 KBi |
#2 |
Correcto
|
0.006 s | 2 KBi |
#3 |
Correcto
|
0.006 s | 2 KBi |
#4 |
Correcto
|
0.006 s | 1 KBi |
#5 |
Correcto
|
0.007 s | 12 KBi |
#6 |
Correcto
|
0.005 s | 2 KBi |
#7 |
Correcto
|
0.005 s | 1 KBi |
#8 |
Correcto
|
0.005 s | 2 KBi |
#9 |
Correcto
|
0.005 s | 1 KBi |
#10 |
Correcto
|
0.094 s | 2 KBi |
#11 |
Correcto
|
0.057 s | 2 KBi |
#12 |
Correcto
|
0.131 s | 2 KBi |
#13 |
Correcto
|
0.042 s | 2 KBi |
#14 |
Correcto
|
0.103 s | 2 KBi |
#15 |
Correcto
|
0.12 s | 2 KBi |
#16 |
Correcto
|
0.063 s | 2 KBi |
#17 |
Correcto
|
0.099 s | 2 KBi |
#18 |
Correcto
|
0.076 s | 2 KBi |
#19 |
Correcto
|
0.07 s | 1 KBi |
#20 |
Correcto
|
0.046 s | 2 KBi |
#21 |
Correcto
|
0.105 s | 2 KBi |
#22 |
Correcto
|
0.086 s | 3 KBi |
#23 |
Correcto
|
0.094 s | 10 KBi |
#24 |
Correcto
|
0.081 s | 1 KBi |
#25 |
Correcto
|
0.102 s | 2 KBi |
#26 |
Correcto
|
0.076 s | 2 KBi |
#27 |
Correcto
|
0.072 s | 2 KBi |
#28 |
Correcto
|
0.077 s | 2 KBi |
#29 |
Correcto
|
0.082 s | 10 KBi |
#30 |
Correcto
|
0.029 s | 2 KBi |
#31 |
Correcto
|
0.038 s | 2 KBi |
#32 |
Correcto
|
0.049 s | 9 KBi |
#include<bits/stdc++.h> using namespace std; int main(){ string see; cin >> see; int k; cin >> k; map<char,int> counter; int ans = 100000000; int i = 0, j = -1; while(j < (int)see.size()){ while(counter.size() == k){ --counter[see[i]]; if(counter[see[i]] == 0) counter.erase(see[i]); ++i; } while(j < (int)see.size() && counter.size() != k){ ++j; ++counter[see[j]]; } while(counter.size() == k){ if(counter[see[i]] != 1) { --counter[see[i]]; ++i; } else break; } if(j != see.size()) ans = min(ans,j-i+1); } if(ans == 100000000) ans = -1; printf("%d\n",ans); return 0; }