This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n,k;
string s;
vector<int> j,o,x;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cin>>n>>k>>s;
int ans=n;
for(int i=0;i<s.size();i++){
if(s[i]=='J')j.push_back(i);
else if(s[i]=='O')o.push_back(i);
else x.push_back(i);
}
for(int i=0;i+k<=j.size();i++){
int now=j[i+k-1];
now=lower_bound(o.begin(),o.end(),now)-o.begin();
if(now+k>o.size())break;
now=o[now+k-1];
now=lower_bound(x.begin(),x.end(),now)-x.begin();
if(now+k>x.size())break;
now=x[now+k-1];
ans=min(now-j[i]+1-k*3,ans);
}
if(ans==n){
cout<<"-1\n";
}else{
cout<<ans<<"\n";
}
return 0;
}
Compilation message (stderr)
ho_t2.cpp: In function 'int main()':
ho_t2.cpp:12:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
12 | for(int i=0;i<s.size();i++){
| ~^~~~~~~~~
ho_t2.cpp:17:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
17 | for(int i=0;i+k<=j.size();i++){
| ~~~^~~~~~~~~~
ho_t2.cpp:20:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
20 | if(now+k>o.size())break;
| ~~~~~^~~~~~~~~
ho_t2.cpp:23:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
23 | if(now+k>x.size())break;
| ~~~~~^~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |