#include <bits/stdc++.h>
#define int long long
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define pb push_back
using namespace std;
signed main(){
int n,k;
cin>>n>>k;
string s;cin>>s;
s=' '+s;
vector <int> v1,v2,v3;
for(int i=1;i<s.size();i++){
if(s[i]=='J')v1.pb(i);
else if(s[i]=='O')v2.pb(i);
else v3.pb(i);
}
vector <pair <int,int> > g1,g3;
for(int i=0;i<v1.size();i++){
if(i+k-1<v1.size()){
g1.pb({v1[i+k-1],v1[i]});
}
}
for(int i=0;i<v3.size();i++){
if(i+k-1<v3.size()){
g3.pb({v3[i],v3[i+k-1]});
}
}
vector <int> ans(v2.size(),-1);
int mn=1e9;
for(int i=0;i<v2.size();i++){
if(i+k-1<v2.size()){
pair <int,int> p={v2[i],0};
auto it=lower_bound(all(g1),p);
if(it!=g1.begin() && g1.size()!=0){
it--;
int ans=v2[i+k-1]-it->ss+1;
p={v2[i+k-1],0};
it=lower_bound(all(g3),p);
if(it!=g3.end()){
ans+=it->ss-v2[i+k-1];
mn=min(mn,ans-3*k);
}
}
}
}
if(mn==1e9)mn=-1;
cout<<mn<<"\n";
}
Compilation message
ho_t2.cpp: In function 'int main()':
ho_t2.cpp:14:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
14 | for(int i=1;i<s.size();i++){
| ~^~~~~~~~~
ho_t2.cpp:20:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
20 | for(int i=0;i<v1.size();i++){
| ~^~~~~~~~~~
ho_t2.cpp:21:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
21 | if(i+k-1<v1.size()){
| ~~~~~^~~~~~~~~~
ho_t2.cpp:25:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | for(int i=0;i<v3.size();i++){
| ~^~~~~~~~~~
ho_t2.cpp:26:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
26 | if(i+k-1<v3.size()){
| ~~~~~^~~~~~~~~~
ho_t2.cpp:32:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
32 | for(int i=0;i<v2.size();i++){
| ~^~~~~~~~~~
ho_t2.cpp:33:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
33 | if(i+k-1<v2.size()){
| ~~~~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
600 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
600 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
600 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
0 ms |
348 KB |
Output is correct |
36 |
Correct |
12 ms |
4524 KB |
Output is correct |
37 |
Correct |
15 ms |
6296 KB |
Output is correct |
38 |
Correct |
16 ms |
6124 KB |
Output is correct |
39 |
Correct |
13 ms |
4752 KB |
Output is correct |
40 |
Correct |
11 ms |
4660 KB |
Output is correct |
41 |
Correct |
16 ms |
4756 KB |
Output is correct |
42 |
Correct |
15 ms |
6292 KB |
Output is correct |
43 |
Correct |
7 ms |
3176 KB |
Output is correct |
44 |
Correct |
7 ms |
3896 KB |
Output is correct |
45 |
Correct |
9 ms |
4500 KB |
Output is correct |
46 |
Correct |
12 ms |
4500 KB |
Output is correct |
47 |
Correct |
11 ms |
4456 KB |
Output is correct |
48 |
Correct |
12 ms |
4500 KB |
Output is correct |
49 |
Correct |
8 ms |
3204 KB |
Output is correct |
50 |
Correct |
9 ms |
4504 KB |
Output is correct |
51 |
Correct |
9 ms |
4484 KB |
Output is correct |
52 |
Correct |
7 ms |
3368 KB |
Output is correct |
53 |
Correct |
8 ms |
3388 KB |
Output is correct |
54 |
Correct |
10 ms |
6568 KB |
Output is correct |
55 |
Correct |
6 ms |
3980 KB |
Output is correct |
56 |
Correct |
5 ms |
3236 KB |
Output is correct |