#include<bits/stdc++.h>
using namespace std;
using i64 = int64_t;
vector<pair<i64, i64>> J;
vector<pair<i64, i64>> O;
vector<pair<i64, i64>> I;
string s;
i64 N, K;
void fun(char c, vector<i64>& poz)
{
for (i64 i = 0; i < N; i++)
{
if (s[i] == c)
{
poz.push_back(i);
}
}
}
int main()
{
//ios_base::sync_with_stdio(0);
//cin.tie(0);
cin >> N >> K >> s;
i64 j = 0, o = 0, i = 0;
for (i64 l = 0; l < N; l++)
{
if (s[l] == 'J') j++;
else if (s[l] == 'O') o++;
else i++;
}
if (j < K || o < K || i < K)
{
cout << "-1\n";
return 0;
}
vector<i64> Jot;
fun('J', Jot);
for (i64 l = K - 1; l < Jot.size(); l++)
{
J.push_back({Jot[l - K + 1], Jot[l]});
}
vector<i64> Oot;
fun('O', Oot);
for (i64 l = K - 1; l < Oot.size(); l++)
{
O.push_back({Oot[l - K + 1], Oot[l]});
}
vector<i64> Iot;
fun('I', Iot);
for (i64 l = K - 1; l < Iot.size(); l++)
{
I.push_back({Iot[l - K + 1], Iot[l]});
}
i64 minn = INT64_MAX;
for (i64 l = 0; l < O.size(); l++)
{
if (J[0].second > O[l].first || I[I.size() - 1].first < O[l].second)
{
continue;
}
//cout << l << " :: " << O[l].first << " : " << O[l].second << "\n";
i64 poczciag, konciag;
i64 pocz = 0, kon = J.size() - 1, srodek;
while (pocz < kon)
{
srodek = (pocz + kon + 1) / 2;
if (J[srodek].second < O[l].first)
{
pocz = srodek;
}
else
{
kon = srodek - 1;
}
}
poczciag = J[pocz].first;
//cout << J[pocz].first << " : " << J[pocz].second << "\n";
pocz = 0, kon = I.size() - 1;
while (pocz < kon)
{
srodek = (pocz + kon) / 2;
if (I[srodek].first > O[l].second)
{
kon = srodek;
}
else
{
pocz = srodek + 1;
}
}
konciag = I[pocz].second;
//cout << I[pocz].first << " : " << I[pocz].second << "\n";
minn = min(minn, konciag - poczciag + 1 - K * 3);
}
if (minn == INT64_MAX)
{
cout << "-1\n";
return 0;
}
cout << minn << "\n";
return 0;
}
Compilation message
ho_t2.cpp: In function 'int main()':
ho_t2.cpp:44:27: warning: comparison of integer expressions of different signedness: 'i64' {aka 'long int'} and 'std::vector<long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
44 | for (i64 l = K - 1; l < Jot.size(); l++)
| ~~^~~~~~~~~~~~
ho_t2.cpp:50:27: warning: comparison of integer expressions of different signedness: 'i64' {aka 'long int'} and 'std::vector<long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | for (i64 l = K - 1; l < Oot.size(); l++)
| ~~^~~~~~~~~~~~
ho_t2.cpp:56:27: warning: comparison of integer expressions of different signedness: 'i64' {aka 'long int'} and 'std::vector<long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | for (i64 l = K - 1; l < Iot.size(); l++)
| ~~^~~~~~~~~~~~
ho_t2.cpp:62:23: warning: comparison of integer expressions of different signedness: 'i64' {aka 'long int'} and 'std::vector<std::pair<long int, long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
62 | for (i64 l = 0; l < O.size(); l++)
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
508 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
508 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
504 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
440 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
1 ms |
336 KB |
Output is correct |
28 |
Correct |
1 ms |
336 KB |
Output is correct |
29 |
Correct |
1 ms |
336 KB |
Output is correct |
30 |
Correct |
1 ms |
336 KB |
Output is correct |
31 |
Correct |
1 ms |
336 KB |
Output is correct |
32 |
Correct |
1 ms |
336 KB |
Output is correct |
33 |
Correct |
1 ms |
336 KB |
Output is correct |
34 |
Correct |
1 ms |
336 KB |
Output is correct |
35 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
508 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
504 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
440 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
1 ms |
336 KB |
Output is correct |
28 |
Correct |
1 ms |
336 KB |
Output is correct |
29 |
Correct |
1 ms |
336 KB |
Output is correct |
30 |
Correct |
1 ms |
336 KB |
Output is correct |
31 |
Correct |
1 ms |
336 KB |
Output is correct |
32 |
Correct |
1 ms |
336 KB |
Output is correct |
33 |
Correct |
1 ms |
336 KB |
Output is correct |
34 |
Correct |
1 ms |
336 KB |
Output is correct |
35 |
Correct |
1 ms |
336 KB |
Output is correct |
36 |
Correct |
19 ms |
6268 KB |
Output is correct |
37 |
Correct |
21 ms |
11048 KB |
Output is correct |
38 |
Correct |
21 ms |
10964 KB |
Output is correct |
39 |
Correct |
20 ms |
6112 KB |
Output is correct |
40 |
Correct |
15 ms |
5476 KB |
Output is correct |
41 |
Correct |
20 ms |
5732 KB |
Output is correct |
42 |
Correct |
20 ms |
11080 KB |
Output is correct |
43 |
Correct |
12 ms |
3176 KB |
Output is correct |
44 |
Correct |
11 ms |
4312 KB |
Output is correct |
45 |
Correct |
17 ms |
5332 KB |
Output is correct |
46 |
Correct |
16 ms |
5220 KB |
Output is correct |
47 |
Correct |
15 ms |
5496 KB |
Output is correct |
48 |
Correct |
16 ms |
5212 KB |
Output is correct |
49 |
Correct |
10 ms |
3432 KB |
Output is correct |
50 |
Correct |
14 ms |
4964 KB |
Output is correct |
51 |
Correct |
15 ms |
5220 KB |
Output is correct |
52 |
Correct |
9 ms |
3024 KB |
Output is correct |
53 |
Correct |
12 ms |
3860 KB |
Output is correct |
54 |
Correct |
15 ms |
11092 KB |
Output is correct |
55 |
Correct |
10 ms |
4180 KB |
Output is correct |
56 |
Correct |
8 ms |
3288 KB |
Output is correct |