#include <bits/stdc++.h>
//#include "horses.h"
using namespace std;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define pb push_back
#define mp make_pair
#define f first
#define s second
int get_ind(char c){
switch(c){
case 'J': return 0;
case 'O': return 1;
case 'I': return 2;
};
}
void solve(){
int n, k;
cin >> n >> k;
string s;
cin >> s;
//[0] - J
//[1] - O
//[2] - I
vector<vi> ind(3);
for(int i = 0; i < n; i++)
ind[get_ind(s[i])].pb(i);
int l = -1, r = 1e9;
for(int i = 0; i < ind[0].size(); i++){
if(i + k - 1 >= ind[0].size())
continue;
int cur = ind[0][i+k-1];
int h = lower_bound(ind[1].begin(), ind[1].end(), cur) - ind[1].begin();
if(h + k - 1 >= ind[1].size())
continue;
cur = ind[1][h+k-1];
h = lower_bound(ind[2].begin(), ind[2].end(), cur) - ind[2].begin();
if(h + k - 1 >= ind[2].size())
continue;
cur = ind[2][h+k-1];
if((cur - ind[0][i]) < (r - l)){
l = ind[0][i];
r = cur;
}
}
if(l == -1)
cout << -1 << '\n';
else {
//cout << l << ' ' << r << ' ' << string(s.begin()+l, s.begin()+r+1) << '\n';
cout << r - l + 1 - 3*k << '\n';
}
}
int main(){
//freopen("input.txt", "r", stdin);
//freopen("test.out", "w", stdout);
ios::sync_with_stdio(0); cin.tie(0);
int t = 1;
//cin >> t;
while(t--){
solve();
}
}
Compilation message
ho_t2.cpp: In function 'void solve()':
ho_t2.cpp:35:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | for(int i = 0; i < ind[0].size(); i++){
| ~~^~~~~~~~~~~~~~~
ho_t2.cpp:36:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
36 | if(i + k - 1 >= ind[0].size())
| ~~~~~~~~~~^~~~~~~~~~~~~~~~
ho_t2.cpp:40:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
40 | if(h + k - 1 >= ind[1].size())
| ~~~~~~~~~~^~~~~~~~~~~~~~~~
ho_t2.cpp:44:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
44 | if(h + k - 1 >= ind[2].size())
| ~~~~~~~~~~^~~~~~~~~~~~~~~~
ho_t2.cpp: In function 'int get_ind(char)':
ho_t2.cpp:21:1: warning: control reaches end of non-void function [-Wreturn-type]
21 | }
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
320 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
320 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
320 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
320 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
316 KB |
Output is correct |
17 |
Correct |
1 ms |
320 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
324 KB |
Output is correct |
22 |
Correct |
1 ms |
316 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
316 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
320 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
320 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
320 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
316 KB |
Output is correct |
17 |
Correct |
1 ms |
320 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
324 KB |
Output is correct |
22 |
Correct |
1 ms |
316 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
316 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
320 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
10 ms |
1588 KB |
Output is correct |
37 |
Correct |
10 ms |
1824 KB |
Output is correct |
38 |
Correct |
11 ms |
1956 KB |
Output is correct |
39 |
Correct |
10 ms |
1988 KB |
Output is correct |
40 |
Correct |
7 ms |
2008 KB |
Output is correct |
41 |
Correct |
8 ms |
1976 KB |
Output is correct |
42 |
Correct |
9 ms |
1824 KB |
Output is correct |
43 |
Correct |
5 ms |
1256 KB |
Output is correct |
44 |
Correct |
5 ms |
1496 KB |
Output is correct |
45 |
Correct |
6 ms |
2008 KB |
Output is correct |
46 |
Correct |
7 ms |
2016 KB |
Output is correct |
47 |
Correct |
7 ms |
2004 KB |
Output is correct |
48 |
Correct |
6 ms |
2016 KB |
Output is correct |
49 |
Correct |
5 ms |
1336 KB |
Output is correct |
50 |
Correct |
7 ms |
1996 KB |
Output is correct |
51 |
Correct |
8 ms |
2008 KB |
Output is correct |
52 |
Correct |
4 ms |
1496 KB |
Output is correct |
53 |
Correct |
4 ms |
1740 KB |
Output is correct |
54 |
Correct |
5 ms |
2012 KB |
Output is correct |
55 |
Correct |
4 ms |
2004 KB |
Output is correct |
56 |
Correct |
3 ms |
2012 KB |
Output is correct |