#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcount
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
const int N = 2e5 + 7;
int n, k;
string s;
int num(char c) {
if (c == 'J')
return 0;
else if (c == 'O')
return 1;
else
return 2;
}
vector <int> pos[N];
int getk(int i, vector <int> &a) {
auto t = lower_bound(all(a), i);
int p = t - a.begin();
if (p + k - 1 >= a.size())
return -1;
else
return a[p + k - 1];
}
signed main() {
#ifdef HOME
freopen("input.txt", "r", stdin);
#else
ios_base::sync_with_stdio(0); cin.tie(0);
#endif
cin >> n >> k >> s;
for (int i = 0; i < n; ++i)
pos[num(s[i])].app(i);
int ans = N;
for (int l = 0; l < n; ++l) {
int t = l;
for (int i = 0; i < 3; ++i) {
t = getk(t, pos[i]);
if (t == -1)
break;
}
if (t != -1)
ans = min(ans, t - l + 1 - 3 * k);
}
if (ans == N)
cout << "-1\n";
else
cout << ans << '\n';
}
Compilation message
ho_t2.cpp: In function 'long long int getk(long long int, std::vector<long long int>&)':
ho_t2.cpp:31:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (p + k - 1 >= a.size())
~~~~~~~~~~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
4984 KB |
Output is correct |
2 |
Correct |
7 ms |
4984 KB |
Output is correct |
3 |
Correct |
7 ms |
4984 KB |
Output is correct |
4 |
Correct |
7 ms |
4984 KB |
Output is correct |
5 |
Correct |
7 ms |
4984 KB |
Output is correct |
6 |
Correct |
7 ms |
4984 KB |
Output is correct |
7 |
Correct |
7 ms |
4984 KB |
Output is correct |
8 |
Correct |
7 ms |
4984 KB |
Output is correct |
9 |
Correct |
7 ms |
4984 KB |
Output is correct |
10 |
Correct |
7 ms |
4984 KB |
Output is correct |
11 |
Correct |
7 ms |
4984 KB |
Output is correct |
12 |
Correct |
7 ms |
5112 KB |
Output is correct |
13 |
Correct |
7 ms |
4984 KB |
Output is correct |
14 |
Correct |
7 ms |
4984 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
4984 KB |
Output is correct |
2 |
Correct |
7 ms |
4984 KB |
Output is correct |
3 |
Correct |
7 ms |
4984 KB |
Output is correct |
4 |
Correct |
7 ms |
4984 KB |
Output is correct |
5 |
Correct |
7 ms |
4984 KB |
Output is correct |
6 |
Correct |
7 ms |
4984 KB |
Output is correct |
7 |
Correct |
7 ms |
4984 KB |
Output is correct |
8 |
Correct |
7 ms |
4984 KB |
Output is correct |
9 |
Correct |
7 ms |
4984 KB |
Output is correct |
10 |
Correct |
7 ms |
4984 KB |
Output is correct |
11 |
Correct |
7 ms |
4984 KB |
Output is correct |
12 |
Correct |
7 ms |
5112 KB |
Output is correct |
13 |
Correct |
7 ms |
4984 KB |
Output is correct |
14 |
Correct |
7 ms |
4984 KB |
Output is correct |
15 |
Correct |
7 ms |
5112 KB |
Output is correct |
16 |
Correct |
7 ms |
5112 KB |
Output is correct |
17 |
Correct |
9 ms |
5112 KB |
Output is correct |
18 |
Correct |
7 ms |
5112 KB |
Output is correct |
19 |
Correct |
7 ms |
5112 KB |
Output is correct |
20 |
Correct |
8 ms |
5112 KB |
Output is correct |
21 |
Correct |
8 ms |
5116 KB |
Output is correct |
22 |
Correct |
7 ms |
5112 KB |
Output is correct |
23 |
Correct |
7 ms |
5112 KB |
Output is correct |
24 |
Correct |
7 ms |
5112 KB |
Output is correct |
25 |
Correct |
7 ms |
5116 KB |
Output is correct |
26 |
Correct |
7 ms |
5112 KB |
Output is correct |
27 |
Correct |
8 ms |
5112 KB |
Output is correct |
28 |
Correct |
7 ms |
5112 KB |
Output is correct |
29 |
Correct |
8 ms |
5112 KB |
Output is correct |
30 |
Correct |
7 ms |
5112 KB |
Output is correct |
31 |
Correct |
7 ms |
5112 KB |
Output is correct |
32 |
Correct |
8 ms |
5112 KB |
Output is correct |
33 |
Correct |
7 ms |
5112 KB |
Output is correct |
34 |
Correct |
7 ms |
5112 KB |
Output is correct |
35 |
Correct |
7 ms |
5112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
4984 KB |
Output is correct |
2 |
Correct |
7 ms |
4984 KB |
Output is correct |
3 |
Correct |
7 ms |
4984 KB |
Output is correct |
4 |
Correct |
7 ms |
4984 KB |
Output is correct |
5 |
Correct |
7 ms |
4984 KB |
Output is correct |
6 |
Correct |
7 ms |
4984 KB |
Output is correct |
7 |
Correct |
7 ms |
4984 KB |
Output is correct |
8 |
Correct |
7 ms |
4984 KB |
Output is correct |
9 |
Correct |
7 ms |
4984 KB |
Output is correct |
10 |
Correct |
7 ms |
4984 KB |
Output is correct |
11 |
Correct |
7 ms |
4984 KB |
Output is correct |
12 |
Correct |
7 ms |
5112 KB |
Output is correct |
13 |
Correct |
7 ms |
4984 KB |
Output is correct |
14 |
Correct |
7 ms |
4984 KB |
Output is correct |
15 |
Correct |
7 ms |
5112 KB |
Output is correct |
16 |
Correct |
7 ms |
5112 KB |
Output is correct |
17 |
Correct |
9 ms |
5112 KB |
Output is correct |
18 |
Correct |
7 ms |
5112 KB |
Output is correct |
19 |
Correct |
7 ms |
5112 KB |
Output is correct |
20 |
Correct |
8 ms |
5112 KB |
Output is correct |
21 |
Correct |
8 ms |
5116 KB |
Output is correct |
22 |
Correct |
7 ms |
5112 KB |
Output is correct |
23 |
Correct |
7 ms |
5112 KB |
Output is correct |
24 |
Correct |
7 ms |
5112 KB |
Output is correct |
25 |
Correct |
7 ms |
5116 KB |
Output is correct |
26 |
Correct |
7 ms |
5112 KB |
Output is correct |
27 |
Correct |
8 ms |
5112 KB |
Output is correct |
28 |
Correct |
7 ms |
5112 KB |
Output is correct |
29 |
Correct |
8 ms |
5112 KB |
Output is correct |
30 |
Correct |
7 ms |
5112 KB |
Output is correct |
31 |
Correct |
7 ms |
5112 KB |
Output is correct |
32 |
Correct |
8 ms |
5112 KB |
Output is correct |
33 |
Correct |
7 ms |
5112 KB |
Output is correct |
34 |
Correct |
7 ms |
5112 KB |
Output is correct |
35 |
Correct |
7 ms |
5112 KB |
Output is correct |
36 |
Correct |
35 ms |
6900 KB |
Output is correct |
37 |
Correct |
38 ms |
7468 KB |
Output is correct |
38 |
Correct |
42 ms |
7472 KB |
Output is correct |
39 |
Correct |
34 ms |
7408 KB |
Output is correct |
40 |
Correct |
30 ms |
7408 KB |
Output is correct |
41 |
Correct |
34 ms |
7536 KB |
Output is correct |
42 |
Correct |
35 ms |
7472 KB |
Output is correct |
43 |
Correct |
20 ms |
6548 KB |
Output is correct |
44 |
Correct |
23 ms |
6612 KB |
Output is correct |
45 |
Correct |
30 ms |
7536 KB |
Output is correct |
46 |
Correct |
29 ms |
7468 KB |
Output is correct |
47 |
Correct |
29 ms |
7408 KB |
Output is correct |
48 |
Correct |
28 ms |
7476 KB |
Output is correct |
49 |
Correct |
22 ms |
6520 KB |
Output is correct |
50 |
Correct |
29 ms |
7472 KB |
Output is correct |
51 |
Correct |
29 ms |
7540 KB |
Output is correct |
52 |
Correct |
21 ms |
6964 KB |
Output is correct |
53 |
Correct |
22 ms |
7528 KB |
Output is correct |
54 |
Correct |
21 ms |
7800 KB |
Output is correct |
55 |
Correct |
19 ms |
7796 KB |
Output is correct |
56 |
Correct |
19 ms |
7800 KB |
Output is correct |