This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
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 ++){
| ~~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |