#define cerr cout
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
// #pragma GCC target("avx,avx2,tune=native")
#include <bits/stdc++.h>
#define endl '\n'
#define all(v) begin(v), end(v)
#define ub upper_bound
#define lb lower_bound
// DBN is defined in /usr/local/Cellar/gcc/11.2.0/include/c++/11.2.0/x86_64-apple-darwin20/bits/stdc++.h
#ifndef tony
#define DBN(...)
#define DBN1D(...)
#define DBN2D(...)
#define dbn(...)
#endif
template<typename T>
using Prior=std::priority_queue<T>;
template<typename T>
using prior=std::priority_queue<T,std::vector<T>,std::greater<T>>;
using namespace std;
typedef long long loli;
typedef vector<loli> vl;
typedef vector<vl> vvl;
typedef pair<loli,loli> pll;
typedef pair<pll,pll> pllll;
typedef vector<pll> vpll;
typedef long double ld;
typedef vector<ld> vld;
typedef vector<bool> vb;
const loli md=1e9+7;
inline loli mod(loli x){
return (x%md+md)%md;
}
void solve(){
int n,k;
cin>>n>>k;
string str;
cin>>str;
vl J,O,I;
for(int i=0;i<n;++i)
if(str[i]=='J')
J.push_back(i);
else if(str[i]=='O')
O.push_back(i);
else
I.push_back(i);
DBN(J,O,I);
loli ans=1e9;
for(int i=0;i+k-1<J.size();++i){
dbn(J[i+k-1]);
auto oit=lb(all(O),J[i+k-1]);
dbn(*oit)
if(O.end()-oit<k)
break;
dbn(*(oit+k-1))
auto iit=lb(all(I),*(oit+k-1)+1);
if(I.end()-iit<k)
break;
dbn(*(iit+k-1),J[i],k*3)
ans=min(ans,*(iit+k-1)-J[i]-k*3+1);
dbn(ans)
dbn(" ")
}
cout<<(ans==1e9?-1:ans)<<endl;
}
int main(){
ios_base::sync_with_stdio(false);cin.tie(0);
int _=1;
// cin>>_;
vl __(_);
iota(all(__),1);
for(auto i:__){
#ifndef tony
//cout<<"Case #"<<i<<": ";
#endif
solve();
#ifdef tony
// break;
cerr<<"=================================================\n";
#endif
}
return 0;
}
Compilation message
ho_t2.cpp: In function 'void solve()':
ho_t2.cpp:58:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
58 | for(int i=0;i+k-1<J.size();++i){
| ~~~~~^~~~~~~~~
ho_t2.cpp: In function 'int main()':
ho_t2.cpp:84:14: warning: unused variable 'i' [-Wunused-variable]
84 | for(auto i:__){
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
316 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
312 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
316 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
312 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
312 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
312 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
1 ms |
332 KB |
Output is correct |
34 |
Correct |
1 ms |
332 KB |
Output is correct |
35 |
Correct |
1 ms |
312 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
316 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
312 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
312 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
312 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
1 ms |
332 KB |
Output is correct |
34 |
Correct |
1 ms |
332 KB |
Output is correct |
35 |
Correct |
1 ms |
312 KB |
Output is correct |
36 |
Correct |
11 ms |
2416 KB |
Output is correct |
37 |
Correct |
12 ms |
2884 KB |
Output is correct |
38 |
Correct |
13 ms |
2860 KB |
Output is correct |
39 |
Correct |
10 ms |
2968 KB |
Output is correct |
40 |
Correct |
6 ms |
3012 KB |
Output is correct |
41 |
Correct |
9 ms |
3012 KB |
Output is correct |
42 |
Correct |
12 ms |
2884 KB |
Output is correct |
43 |
Correct |
3 ms |
1824 KB |
Output is correct |
44 |
Correct |
3 ms |
1992 KB |
Output is correct |
45 |
Correct |
6 ms |
2952 KB |
Output is correct |
46 |
Correct |
5 ms |
2952 KB |
Output is correct |
47 |
Correct |
5 ms |
3012 KB |
Output is correct |
48 |
Correct |
5 ms |
2984 KB |
Output is correct |
49 |
Correct |
3 ms |
1860 KB |
Output is correct |
50 |
Correct |
5 ms |
2984 KB |
Output is correct |
51 |
Correct |
5 ms |
3012 KB |
Output is correct |
52 |
Correct |
4 ms |
2356 KB |
Output is correct |
53 |
Correct |
5 ms |
2880 KB |
Output is correct |
54 |
Correct |
7 ms |
3280 KB |
Output is correct |
55 |
Correct |
5 ms |
3272 KB |
Output is correct |
56 |
Correct |
3 ms |
3308 KB |
Output is correct |