#include<bits/stdc++.h>
#define pii pair<int,int>
#define ll long long
using namespace std;
int bs(int lo,int hi,int *ar,int k)
{
int in;
if(lo>0)in=ar[lo-1];
else in=0;
int rs=-1;
//cout<<ar[1]<<endl;
while(lo<=hi)
{
int mid=lo+hi>>1;
if(ar[mid]-in>=k)
{
rs=mid;
hi=mid-1;
}
else lo=mid+1;
}
return rs;
}
int main()
{
int n,k;
cin>>n>>k;
string s;
cin>>s;
int J[n]={};
int O[n]={};
int I[n]={};
if(s[0]=='J')J[0]++;
else if(s[0]=='O')O[0]++;
else I[0]++;
int ans=1e9+10;
for(int i=1;i<n;i++)
{
J[i]=J[i-1];
O[i]=O[i-1];
I[i]=I[i-1];
if(s[i]=='J')J[i]++;
else if(s[i]=='O')O[i]++;
else I[i]++;
}
for(int i=0;i<n;i++)
{
if(s[i]!='J')continue;
int n1=bs(i,n-1,J,k);
if(n1==-1)continue;
int n2=bs(n1+1,n-1,O,k);
if(n2==-1)continue;
int n3=bs(n2+1,n-1,I,k);
if(n3==-1)continue;
int d=n3-i+1;
d-=3*k;
ans=min(d,ans);
}
if(ans==1e9+10)cout<<-1<<endl;
else cout<<ans<<endl;
return 0;
}
Compilation message
ho_t2.cpp: In function 'int bs(int, int, int*, int)':
ho_t2.cpp:16:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid=lo+hi>>1;
~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
4 ms |
248 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
256 KB |
Output is correct |
8 |
Correct |
5 ms |
256 KB |
Output is correct |
9 |
Correct |
5 ms |
256 KB |
Output is correct |
10 |
Correct |
5 ms |
296 KB |
Output is correct |
11 |
Correct |
4 ms |
256 KB |
Output is correct |
12 |
Correct |
5 ms |
256 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
4 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
4 ms |
248 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
256 KB |
Output is correct |
8 |
Correct |
5 ms |
256 KB |
Output is correct |
9 |
Correct |
5 ms |
256 KB |
Output is correct |
10 |
Correct |
5 ms |
296 KB |
Output is correct |
11 |
Correct |
4 ms |
256 KB |
Output is correct |
12 |
Correct |
5 ms |
256 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
4 ms |
256 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
5 ms |
376 KB |
Output is correct |
18 |
Correct |
5 ms |
376 KB |
Output is correct |
19 |
Correct |
5 ms |
376 KB |
Output is correct |
20 |
Correct |
6 ms |
376 KB |
Output is correct |
21 |
Correct |
5 ms |
376 KB |
Output is correct |
22 |
Correct |
5 ms |
376 KB |
Output is correct |
23 |
Correct |
5 ms |
376 KB |
Output is correct |
24 |
Correct |
6 ms |
376 KB |
Output is correct |
25 |
Correct |
5 ms |
376 KB |
Output is correct |
26 |
Correct |
6 ms |
376 KB |
Output is correct |
27 |
Correct |
5 ms |
376 KB |
Output is correct |
28 |
Correct |
7 ms |
376 KB |
Output is correct |
29 |
Correct |
5 ms |
376 KB |
Output is correct |
30 |
Correct |
6 ms |
376 KB |
Output is correct |
31 |
Correct |
5 ms |
376 KB |
Output is correct |
32 |
Correct |
6 ms |
376 KB |
Output is correct |
33 |
Correct |
5 ms |
376 KB |
Output is correct |
34 |
Correct |
5 ms |
376 KB |
Output is correct |
35 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
256 KB |
Output is correct |
3 |
Correct |
4 ms |
248 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
5 ms |
256 KB |
Output is correct |
8 |
Correct |
5 ms |
256 KB |
Output is correct |
9 |
Correct |
5 ms |
256 KB |
Output is correct |
10 |
Correct |
5 ms |
296 KB |
Output is correct |
11 |
Correct |
4 ms |
256 KB |
Output is correct |
12 |
Correct |
5 ms |
256 KB |
Output is correct |
13 |
Correct |
5 ms |
376 KB |
Output is correct |
14 |
Correct |
4 ms |
256 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
5 ms |
376 KB |
Output is correct |
18 |
Correct |
5 ms |
376 KB |
Output is correct |
19 |
Correct |
5 ms |
376 KB |
Output is correct |
20 |
Correct |
6 ms |
376 KB |
Output is correct |
21 |
Correct |
5 ms |
376 KB |
Output is correct |
22 |
Correct |
5 ms |
376 KB |
Output is correct |
23 |
Correct |
5 ms |
376 KB |
Output is correct |
24 |
Correct |
6 ms |
376 KB |
Output is correct |
25 |
Correct |
5 ms |
376 KB |
Output is correct |
26 |
Correct |
6 ms |
376 KB |
Output is correct |
27 |
Correct |
5 ms |
376 KB |
Output is correct |
28 |
Correct |
7 ms |
376 KB |
Output is correct |
29 |
Correct |
5 ms |
376 KB |
Output is correct |
30 |
Correct |
6 ms |
376 KB |
Output is correct |
31 |
Correct |
5 ms |
376 KB |
Output is correct |
32 |
Correct |
6 ms |
376 KB |
Output is correct |
33 |
Correct |
5 ms |
376 KB |
Output is correct |
34 |
Correct |
5 ms |
376 KB |
Output is correct |
35 |
Correct |
5 ms |
376 KB |
Output is correct |
36 |
Correct |
26 ms |
2824 KB |
Output is correct |
37 |
Correct |
25 ms |
2952 KB |
Output is correct |
38 |
Correct |
28 ms |
2952 KB |
Output is correct |
39 |
Correct |
32 ms |
2984 KB |
Output is correct |
40 |
Correct |
25 ms |
2952 KB |
Output is correct |
41 |
Correct |
29 ms |
2952 KB |
Output is correct |
42 |
Correct |
28 ms |
2948 KB |
Output is correct |
43 |
Correct |
18 ms |
2056 KB |
Output is correct |
44 |
Correct |
20 ms |
2444 KB |
Output is correct |
45 |
Correct |
25 ms |
2952 KB |
Output is correct |
46 |
Correct |
24 ms |
2952 KB |
Output is correct |
47 |
Correct |
24 ms |
2952 KB |
Output is correct |
48 |
Correct |
24 ms |
3128 KB |
Output is correct |
49 |
Correct |
18 ms |
2184 KB |
Output is correct |
50 |
Correct |
26 ms |
2952 KB |
Output is correct |
51 |
Correct |
25 ms |
3080 KB |
Output is correct |
52 |
Correct |
20 ms |
2956 KB |
Output is correct |
53 |
Correct |
21 ms |
2952 KB |
Output is correct |
54 |
Correct |
24 ms |
2952 KB |
Output is correct |
55 |
Correct |
21 ms |
2952 KB |
Output is correct |
56 |
Correct |
21 ms |
2952 KB |
Output is correct |