#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);
}
}
if(ans==n+1)
{
cout<<-1<<endl;
}
else
{
cout<<ans<<endl;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2029 ms |
344 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2029 ms |
344 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2029 ms |
344 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |