# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1000015 |
2024-06-16T13:07:16 Z |
IWTIM |
JJOOII 2 (JOI20_ho_t2) |
C++17 |
|
20 ms |
8768 KB |
# include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
const int N = 1e6 + 5;
int t,n,k,prefo[N],prefj[N],prefi[N],st,l,r,idx,mid,ans;
string s;
signed main() {
ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
cin>>n>>k;
cin>>s;
s="@"+s;
for(int i=1;i<=n;i++){
prefj[i]=prefj[i-1]+(s[i]=='J');
prefo[i]=prefo[i-1]+(s[i]=='O');
prefi[i]=prefi[i-1]+(s[i]=='I');
}
ans=1e9;
for (int i=1;i<=n;i++) {
st=i;
l=i; r=n;
idx=-1;
while(l<=r){
mid=(l+r)/2;
if(prefj[mid]-prefj[st-1]>=k){
idx=mid;
r=mid-1;
}
else{
l=mid+1;
}
}
if (idx==-1) break;
st=idx+1;
l=st; r=n;
idx=-1;
while(l<=r){
mid=(l+r)/2;
if(prefo[mid]-prefo[st-1]>=k){
idx=mid;
r=mid-1;
}
else{
l=mid+1;
}
}
if(idx==-1) break;
st=idx+1;
l=st; r=n;
idx=-1;
while(l<=r){
mid=(l+r)/2;
if(prefi[mid]-prefi[st-1]>=k){
idx=mid;
r=mid-1;
}
else{
l=mid+1;
}
}
if(idx==-1) break;
ans=min(ans, idx-i+1-3*k);
}
if (ans==1e9) cout<<-1;
else cout<<ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
600 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
1 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
600 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
1 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
15 ms |
8752 KB |
Output is correct |
37 |
Correct |
17 ms |
8740 KB |
Output is correct |
38 |
Correct |
15 ms |
8740 KB |
Output is correct |
39 |
Correct |
15 ms |
8768 KB |
Output is correct |
40 |
Correct |
6 ms |
8648 KB |
Output is correct |
41 |
Correct |
12 ms |
8736 KB |
Output is correct |
42 |
Correct |
20 ms |
8612 KB |
Output is correct |
43 |
Correct |
2 ms |
8540 KB |
Output is correct |
44 |
Correct |
2 ms |
8660 KB |
Output is correct |
45 |
Correct |
2 ms |
8740 KB |
Output is correct |
46 |
Correct |
2 ms |
8740 KB |
Output is correct |
47 |
Correct |
3 ms |
8740 KB |
Output is correct |
48 |
Correct |
3 ms |
8740 KB |
Output is correct |
49 |
Correct |
2 ms |
8548 KB |
Output is correct |
50 |
Correct |
3 ms |
8744 KB |
Output is correct |
51 |
Correct |
3 ms |
8740 KB |
Output is correct |
52 |
Correct |
2 ms |
8748 KB |
Output is correct |
53 |
Correct |
2 ms |
8736 KB |
Output is correct |
54 |
Correct |
7 ms |
8740 KB |
Output is correct |
55 |
Correct |
4 ms |
8728 KB |
Output is correct |
56 |
Correct |
2 ms |
8740 KB |
Output is correct |