#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, k;
cin >> n >> k;
string s;
cin >> s;
int L, R;
vector<int> posj, poso, posi;
int pos[n];
for(int i=0; i< n; i++){
if(s[i]=='J'){
posj.pb(i);
pos[i]=posj.size()-1;
}
else if(s[i]=='O'){
poso.pb(i);
pos[i]=poso.size()-1;
}
else{
posi.pb(i);
pos[i]=posi.size()-1;
}
}
int szj, szo, szi;
szj=posj.size(); szo=poso.size(); szi=posi.size();
int ans=1e9;
for(int i=0; i+k<=szj; i++){
int ind=posj[i+k-1];
auto its=upper_bound(poso.begin(), poso.end(), ind);
if(its==poso.end())break;
int ind2=*its;
ind2=pos[ind2];
ind2+=k-1;
if(ind2>=szo)break;
its=upper_bound(posi.begin(), posi.end(), poso[ind2]);
if(its==posi.end())break;
int ind3=*its;
ind3=pos[ind3];
ind3+=k-1;
if(ind3>=szi)break;
ans=min(ans, posi[ind3]-posj[i]-3*k+1);
}
if(ans>1e8)cout << -1 << '\n';
else cout << ans << '\n';
}
Compilation message
ho_t2.cpp: In function 'int main()':
ho_t2.cpp:17:9: warning: unused variable 'L' [-Wunused-variable]
17 | int L, R;
| ^
ho_t2.cpp:17:12: warning: unused variable 'R' [-Wunused-variable]
17 | int L, R;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 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 |
452 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 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 |
452 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
464 KB |
Output is correct |
24 |
Correct |
1 ms |
344 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
596 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
344 KB |
Output is correct |
31 |
Correct |
1 ms |
344 KB |
Output is correct |
32 |
Correct |
1 ms |
344 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
1 ms |
344 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 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 |
452 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
464 KB |
Output is correct |
24 |
Correct |
1 ms |
344 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
596 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
344 KB |
Output is correct |
31 |
Correct |
1 ms |
344 KB |
Output is correct |
32 |
Correct |
1 ms |
344 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
1 ms |
344 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
8 ms |
3904 KB |
Output is correct |
37 |
Correct |
10 ms |
4564 KB |
Output is correct |
38 |
Correct |
10 ms |
4396 KB |
Output is correct |
39 |
Correct |
8 ms |
4520 KB |
Output is correct |
40 |
Correct |
6 ms |
4564 KB |
Output is correct |
41 |
Correct |
7 ms |
4564 KB |
Output is correct |
42 |
Correct |
9 ms |
4564 KB |
Output is correct |
43 |
Correct |
3 ms |
2940 KB |
Output is correct |
44 |
Correct |
3 ms |
3288 KB |
Output is correct |
45 |
Correct |
4 ms |
4504 KB |
Output is correct |
46 |
Correct |
4 ms |
4504 KB |
Output is correct |
47 |
Correct |
4 ms |
4680 KB |
Output is correct |
48 |
Correct |
4 ms |
4492 KB |
Output is correct |
49 |
Correct |
3 ms |
3028 KB |
Output is correct |
50 |
Correct |
4 ms |
4536 KB |
Output is correct |
51 |
Correct |
4 ms |
4564 KB |
Output is correct |
52 |
Correct |
4 ms |
4036 KB |
Output is correct |
53 |
Correct |
4 ms |
4428 KB |
Output is correct |
54 |
Correct |
4 ms |
4832 KB |
Output is correct |
55 |
Correct |
3 ms |
4832 KB |
Output is correct |
56 |
Correct |
3 ms |
4832 KB |
Output is correct |