# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
207832 | kai824 | JJOOII 2 (JOI20_ho_t2) | C++17 | 16 ms | 1916 KiB |
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"
using namespace std;
vector<int> js,os,is;//store indexes...
int32_t main() {
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int n,k,b1,b2,b3,ans=INT_MAX;
string s;
cin>>n>>k>>s;
for(int i=0;i<n;i++){
if(s[i]=='J')js.push_back(i);
else if(s[i]=='O')os.push_back(i);
else is.push_back(i);
}
for(int i=k-1;i<is.size();i++){//must contain at least k of each kind...
b1=is[i-(k-1)];//first break point...
b1=(lower_bound(os.begin(),os.end(),b1)-os.begin()) -k;//index in os...
if(b1<0)continue;
b2=os[b1];
b2=(lower_bound(js.begin(),js.end(),b2)-js.begin()) -k;//index in js...
if(b2<0)continue;
b2=js[b2];
ans=min(is[i]-b2+1,ans);
}
if(ans==INT_MAX)cout<<"-1\n";
else cout<<ans-(k*3)<<'\n';
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |