#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;
const int N = 100001,INF=1e12;
int32_t main()
{
//freopen("abc.in", "r", stdin);
int n , k ;
cin >> n >> k;
string s;
cin>>s;
vector<int>J(n),I(n),O(n);
for(int i = 0 ; i < s.size() ; i ++){
if(s[i]=='J') J[i]++;
if(s[i]=='O') O[i]++;
if(s[i]=='I') I[i]++;
if(i) J[i]+=J[i-1],I[i]+=I[i-1],O[i]+=O[i-1];
}
int ans=INT_MAX;
for(int i = 0 ; i < n ; i ++)
{
int start = i ;
int cons=J[i]; if(s[i]=='J') cons--;
auto it = lower_bound(J.begin(),J.end(),cons+k);
if(it==J.end()) break;
int ptr2 = it-J.begin();
it = lower_bound(O.begin(),O.end(),O[ptr2]+k);
if(it==O.end()) break;
int ptr3 = it-O.begin();
it = lower_bound(I.begin(),I.end(),I[ptr3]+k);
if(it==I.end()) break;
int ptr4 = it-I.begin();
ans=min(ans,(ptr4-start+1)-(k*3));
}
cout<<ans;
}
Compilation message
ho_t2.cpp: In function 'int32_t main()':
ho_t2.cpp:14:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
14 | for(int i = 0 ; i < s.size() ; i ++){
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
296 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
300 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
296 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
300 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
296 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
300 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |