# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
657376 |
2022-11-09T18:10:13 Z |
inwbear |
JJOOII 2 (JOI20_ho_t2) |
C++14 |
|
13 ms |
1784 KB |
#include<bits/stdc++.h>
using namespace std;
vector<int>v[3];
int n,k;
string s;
int main(){
cin>>n>>k;
cin>>s;
for(int i=0;i<n;i++){
if(s[i]=='J'){
v[0].push_back(i);
}else if(s[i]=='O'){
v[1].push_back(i);
}else{
v[2].push_back(i);
}
}
int min=INT_MAX;
for(int i=k-1;i<v[0].size();i++){
int comp=v[0][i];
int x=-1;
//printf("[j:%d]",comp);
int st=0,en=v[1].size()-1;
while(st<=en){
//printf("-%d-",comp);
int mid=(st+en)/2;
if(v[1][mid]>comp){
//printf("[=%d %d=]",v[1][mid],comp);
en=mid-1;
x=mid;
}else{
st=mid+1;
}
}
if(x==-1){
break;
}
x+=k-1;
if(x>=v[1].size()){
break;
}
int y=0;
comp=v[1][x];
//printf("[O:%d]",comp);
st=0,en=v[2].size()-1;
while(st<=en){
int mid=(st+en)/2;
if(v[2][mid]>comp){
en=mid-1;
x=mid;
y=1;
}else{
st=mid+1;
}
}
if(y!=1){
break;
}
x+=k-1;
if(x>=v[2].size()){
break;
}
int ans=v[2][x]-(v[0][i-k+1])+1-3*k;
if(ans<min){
//cout<<v[2][x]<<" "<<(v[0][i-k+1])<<endl;
min=ans;
}
}
if(min!=INT_MAX){
cout<<min;
}else{
cout<<"-1";
}
}
Compilation message
ho_t2.cpp: In function 'int main()':
ho_t2.cpp:19:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
19 | for(int i=k-1;i<v[0].size();i++){
| ~^~~~~~~~~~~~
ho_t2.cpp:39:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
39 | if(x>=v[1].size()){
| ~^~~~~~~~~~~~~
ho_t2.cpp:60:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
60 | if(x>=v[2].size()){
| ~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Correct |
0 ms |
212 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
0 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
1 ms |
228 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Correct |
0 ms |
212 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
0 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
1 ms |
228 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
12 ms |
1252 KB |
Output is correct |
37 |
Correct |
13 ms |
1564 KB |
Output is correct |
38 |
Correct |
13 ms |
1708 KB |
Output is correct |
39 |
Correct |
11 ms |
1732 KB |
Output is correct |
40 |
Correct |
8 ms |
1756 KB |
Output is correct |
41 |
Correct |
10 ms |
1744 KB |
Output is correct |
42 |
Correct |
13 ms |
1568 KB |
Output is correct |
43 |
Correct |
5 ms |
1116 KB |
Output is correct |
44 |
Correct |
7 ms |
1372 KB |
Output is correct |
45 |
Correct |
8 ms |
1772 KB |
Output is correct |
46 |
Correct |
8 ms |
1744 KB |
Output is correct |
47 |
Correct |
7 ms |
1752 KB |
Output is correct |
48 |
Correct |
8 ms |
1752 KB |
Output is correct |
49 |
Correct |
5 ms |
1080 KB |
Output is correct |
50 |
Correct |
7 ms |
1632 KB |
Output is correct |
51 |
Correct |
7 ms |
1500 KB |
Output is correct |
52 |
Correct |
6 ms |
1380 KB |
Output is correct |
53 |
Correct |
7 ms |
1484 KB |
Output is correct |
54 |
Correct |
7 ms |
1784 KB |
Output is correct |
55 |
Correct |
6 ms |
1760 KB |
Output is correct |
56 |
Correct |
6 ms |
1760 KB |
Output is correct |