#include <bits/stdc++.h>
using namespace std;
int main()
{
int n, k, m=-1, x, y, z, t, i;
string s;
cin >> n >> k >> s;
int aj[n], ao[n], ai[n];
if (s[0]=='J')
{
aj[0]=1;
ao[0]=1;
ai[0]=1;
}
if (s[0]=='O')
{
aj[0]=0;
ao[0]=1;
ai[0]=0;
}
if (s[0]=='I')
{
aj[0]=0;
ao[0]=0;
ai[0]=1;
}
for (i=1; i<n; i++)
{
if (s[i]=='J')
aj[i]=aj[i-1]+1;
else
aj[i]=aj[i-1];
}
for (i=1; i<n; i++)
{
if (s[i]=='O')
ao[i]=ao[i-1]+1;
else
ao[i]=ao[i-1];
}
for (i=1; i<n; i++)
{
if (s[i]=='I')
ai[i]=ai[i-1]+1;
else
ai[i]=ai[i-1];
}
for (i=0; i<n; i++)
if (s[i]=='J')
{
if (i!=0)
t=k+aj[i-1];
else
t=k;
x=lower_bound(aj, aj+n, t)-aj;
if (x==n)
continue;
t=k+aj[x-1];
y=lower_bound(ao, ao+n, t)-ao;
if (y==n)
continue;
t=k+ao[y-1];
z=lower_bound(ai, ai+n, t)-ai;
if (z==n)
continue;
if (m==-1 || z-i+1-3*k<m)
m=z-i+1-3*k;
}
cout << m;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |