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
#define ff first
#define ss second
#define pb push_back
using namespace std;
const int N = 1e6 + 69;
int n,x,k,l,r;
int B[N],ANS[N];
int A[N],ans;
vector<int> v[3];
int main(){
cin>>n>>k;
for(int i=1;i<=n;i++){
char c;
cin>>c;
if(c == 'J') A[i] = 0;
if(c == 'O') A[i] = 1;
if(c == 'I') A[i] = 2;
v[ A[i] ].pb(i);
}
ans = 1e9;
for(int i=0;i<v[0].size()-k+1;i++){
l = v[0][i];
r = v[0][i+k-1];
bool ok = true;
for(int j=1;j<=2;j++){
vector<int> :: iterator it;
it = upper_bound(v[j].begin(),v[j].end(),r);
if(it == v[j].end()){
ok = false;
break;
}
if(it-v[j].begin()+k-1 >= v[j].size()){
ok = false;
break;
}
r = v[j][it-v[j].begin()+k-1];
}
if(!ok){
break;
}
ans = min(ans,r-l-3*k+1);
}
if(ans == 1e9){
ans = -1;
}
cout<<ans<<endl;
}
Compilation message (stderr)
ho_t2.cpp: In function 'int main()':
ho_t2.cpp:32:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<v[0].size()-k+1;i++){
~^~~~~~~~~~~~~~~~
ho_t2.cpp:49:36: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(it-v[j].begin()+k-1 >= v[j].size()){
~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |