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 NMAX 500001
#define pb push_back
#define MOD 1000000007
#define nl '\n'
#define INF 0x3f3f3f3f
#define pii pair<int,int>
using namespace std;
ifstream fin("aib.in");
ofstream fout("aib.out");
int n,k,ans=INF;
string s;
vector<int>v[NMAX],cnt(NMAX);
int J='J'-'0';
int O='O'-'0';
int I='I'-'0';
signed main() {
cin>>n>>k;
cin>>s;
s="#"+s;
for(int i=1;i<=n;++i)
{
v[s[i]-'0'].pb(i);
cnt[s[i]-'0']++;
// cout<<s[i];
}
if(v[J].size()<k||v[O].size()<k||v[I].size()<k)
{
cout<<-1;
return 0;
}
for(int i=0;i<cnt[J]-k+1;++i)
{
int cur=v[J][i];
int it_J=v[J][i+k-1];
//cout<<cur<<" "<<it_J<<nl;
auto it_O=upper_bound(v[O].begin(),v[O].end(),it_J);
advance(it_O,k-1);
if(it_O==v[O].end())
continue;
//cout<<*it_O<<" ";
auto it_I=upper_bound(v[I].begin(),v[I].end(),*it_O);
advance(it_I,k-1);
if(it_I==v[I].end())
continue;
//cout<<cur<<" "<<*it_O<<" "<<*it_I<<nl;
ans=min(ans,(*it_I-cur+1)-3*k);
}
if(ans==INF)
cout<<-1;
else
cout<<ans;
return 0;
}
Compilation message (stderr)
ho_t2.cpp: In function 'int main()':
ho_t2.cpp:30:19: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
30 | if(v[J].size()<k||v[O].size()<k||v[I].size()<k)
| ~~~~~~~~~~~^~
ho_t2.cpp:30:34: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
30 | if(v[J].size()<k||v[O].size()<k||v[I].size()<k)
| ~~~~~~~~~~~^~
ho_t2.cpp:30:49: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
30 | if(v[J].size()<k||v[O].size()<k||v[I].size()<k)
| ~~~~~~~~~~~^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |