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 <iostream>
using namespace std;
int n,k,pj[200010],po[200010],pi[200010],aj,ao,ai,nrj,nro,nri,ans=-1;
char c;
int main()
{
cin>>n>>k;
for(int i=1;i<=n;++i)
{
cin>>c;
if(c=='J')
pj[++nrj]=i;
if(c=='O')
po[++nro]=i;
if(c=='I')
pi[++nri]=i;
}
int c=nri,a=nrj,b=nro;
for(int c=nri;c>=k;--c)
{
while(pi[c-k+1]<po[b])
--b;
if(b<k)
break;
while(po[b-k+1]<pj[a])
--a;
if(a<k)
break;
if(ans==-1||ans>pi[c]-pj[a-k+1]+1-3*k)
ans=pi[c]-pj[a-k+1]+1-3*k;
}
cout<<ans;
return 0;
}
Compilation message (stderr)
ho_t2.cpp: In function 'int main()':
ho_t2.cpp:18:9: warning: unused variable 'c' [-Wunused-variable]
18 | int c=nri,a=nrj,b=nro;
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |