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>
using namespace std;
#define int long long
const long long maxn = 2e5 + 5;
const long long logn=25;
const long long mod=1e9+7;
int vJ[maxn];
int vO[maxn];
int vI[maxn];
int cj=0;
int ci=0;
int co=0;
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n,k;
cin>>n>>k;
string s;
cin>>s;
for(int i=0;i<n;i++)
{
if(s[i]=='J')
{
cj++;
vJ[cj]=i;
}
if(s[i]=='O')
{
co++;
vO[co]=i;
}
if(s[i]=='I')
{
ci++;
vI[ci]=i;
}
}
int pj=1;
int po=1;
int pi=1;
int ans=n+1;
while(pj+k-1<=cj && po+k-1<=co && pi+k-1<=ci)
{
while(po+k-1<=co && vO[po]<=vJ[pj+k-1])
{
po++;
}
if(po+k-1<=co)
{
while(pi-k+1<=ci && vI[pi]<=vO[po+k-1])
{
pi++;
}
}
if(pj+k-1<=cj && po+k-1<=co && pi+k-1<=ci)
{
ans=min(ans,vI[pi+k-1]-vJ[pj]+1-3*k);
}
pj++;
}
if(ans==n+1)
{
cout<<-1<<endl;
}
else
{
cout<<ans<<endl;
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |