#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <iomanip>
#include <cmath>
#include <queue>
#include <bitset>
#include <numeric>
#include <array>
#include <cstring>
#include <random>
#include <chrono>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())
typedef long long ll;
typedef long double ld;
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int main() {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n = 0, k = 0;
string s;
cin >> n >> k >> s;
int ans = -1;
vector<int> pos[3];
for(int i = 0; i < n; i++) {
if(s[i] == 'J') pos[0].pb(i);
else if(s[i] == 'O') pos[1].pb(i);
else pos[2].pb(i);
}
int jp = 0, op = 0, ip = 0;
for(; jp < pos[0].size(); jp++) {
if(jp + k - 1 >= pos[0].size()) break;
while(op < pos[1].size() && pos[1][op] < pos[0][jp + k - 1]) op++;
if(op == pos[1].size() || op > pos[0][jp + k - 1]) break;
if(op + k - 1 >= pos[1].size()) break;
while(ip < pos[2].size() && pos[2][ip] < pos[1][op + k - 1]) ip++;
if(ip + k - 1 >= pos[2].size()) break;
ans = (ans == -1 ? pos[2][ip + k - 1] - pos[0][jp] + 1 - 3 * k : min(ans, pos[2][ip + k - 1] - pos[0][jp] + 1 - 3 * k));
}
cout << ans;
return 0;
}
/*
*/
Compilation message
ho_t2.cpp:3:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
#pragma GCC optimization ("unroll-loops")
ho_t2.cpp: In function 'int main()':
ho_t2.cpp:53:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(; jp < pos[0].size(); jp++) {
~~~^~~~~~~~~~~~~~~
ho_t2.cpp:54:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(jp + k - 1 >= pos[0].size()) break;
~~~~~~~~~~~^~~~~~~~~~~~~~~~
ho_t2.cpp:55:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(op < pos[1].size() && pos[1][op] < pos[0][jp + k - 1]) op++;
~~~^~~~~~~~~~~~~~~
ho_t2.cpp:56:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(op == pos[1].size() || op > pos[0][jp + k - 1]) break;
~~~^~~~~~~~~~~~~~~~
ho_t2.cpp:57:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(op + k - 1 >= pos[1].size()) break;
~~~~~~~~~~~^~~~~~~~~~~~~~~~
ho_t2.cpp:58:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(ip < pos[2].size() && pos[2][ip] < pos[1][op + k - 1]) ip++;
~~~^~~~~~~~~~~~~~~
ho_t2.cpp:59:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(ip + k - 1 >= pos[2].size()) break;
~~~~~~~~~~~^~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
512 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
360 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
2 ms |
384 KB |
Output is correct |
25 |
Correct |
1 ms |
384 KB |
Output is correct |
26 |
Correct |
1 ms |
384 KB |
Output is correct |
27 |
Correct |
1 ms |
384 KB |
Output is correct |
28 |
Correct |
1 ms |
384 KB |
Output is correct |
29 |
Correct |
1 ms |
384 KB |
Output is correct |
30 |
Correct |
2 ms |
384 KB |
Output is correct |
31 |
Correct |
1 ms |
384 KB |
Output is correct |
32 |
Correct |
1 ms |
384 KB |
Output is correct |
33 |
Correct |
1 ms |
384 KB |
Output is correct |
34 |
Correct |
1 ms |
512 KB |
Output is correct |
35 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
512 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
360 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
2 ms |
384 KB |
Output is correct |
25 |
Correct |
1 ms |
384 KB |
Output is correct |
26 |
Correct |
1 ms |
384 KB |
Output is correct |
27 |
Correct |
1 ms |
384 KB |
Output is correct |
28 |
Correct |
1 ms |
384 KB |
Output is correct |
29 |
Correct |
1 ms |
384 KB |
Output is correct |
30 |
Correct |
2 ms |
384 KB |
Output is correct |
31 |
Correct |
1 ms |
384 KB |
Output is correct |
32 |
Correct |
1 ms |
384 KB |
Output is correct |
33 |
Correct |
1 ms |
384 KB |
Output is correct |
34 |
Correct |
1 ms |
512 KB |
Output is correct |
35 |
Correct |
1 ms |
384 KB |
Output is correct |
36 |
Correct |
7 ms |
1540 KB |
Output is correct |
37 |
Correct |
6 ms |
1880 KB |
Output is correct |
38 |
Correct |
6 ms |
2036 KB |
Output is correct |
39 |
Correct |
8 ms |
2052 KB |
Output is correct |
40 |
Correct |
5 ms |
2020 KB |
Output is correct |
41 |
Correct |
6 ms |
2036 KB |
Output is correct |
42 |
Correct |
6 ms |
1924 KB |
Output is correct |
43 |
Correct |
6 ms |
1376 KB |
Output is correct |
44 |
Correct |
4 ms |
1524 KB |
Output is correct |
45 |
Correct |
6 ms |
2052 KB |
Output is correct |
46 |
Correct |
5 ms |
1920 KB |
Output is correct |
47 |
Correct |
5 ms |
2052 KB |
Output is correct |
48 |
Correct |
7 ms |
2052 KB |
Output is correct |
49 |
Correct |
3 ms |
1292 KB |
Output is correct |
50 |
Correct |
5 ms |
1924 KB |
Output is correct |
51 |
Correct |
6 ms |
1924 KB |
Output is correct |
52 |
Correct |
4 ms |
1608 KB |
Output is correct |
53 |
Correct |
5 ms |
1864 KB |
Output is correct |
54 |
Correct |
3 ms |
2052 KB |
Output is correct |
55 |
Correct |
3 ms |
2052 KB |
Output is correct |
56 |
Correct |
4 ms |
2052 KB |
Output is correct |