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 fi first
#define se second
#define pb push_back
#define int long long
#define lf (id<<1)
#define rg ((id<<1)|1)
#define md ((l+r)>>1)
using namespace std;
typedef pair<int,int> pii;
typedef pair<string, pii> ipii;
const int INF = 1e9+10;
const int MAXN = 1e6+10;
int n, k;
int O[MAXN], I[MAXN];
string s;
int mn = INF;
vector <int> vec;
void f(int idx, int fr){
int l=idx, r=n, cnt=-1, mid=0;
while(l<=r){
mid = md;
if(O[idx]-O[mid+1] >= k){ // ke kiri
r = mid-1; cnt = mid;
} else l = mid+1;
}
int ido = cnt;
if(ido == -1) return;
//cout << ido << " O\n";
l = cnt, r=n, cnt=-1, mid=0;
while(l<=r){
mid = md;
if(I[ido]-I[mid+1] >= k){
r = mid-1; cnt = mid;
} else l = mid+1;
}
if(cnt == -1) return;
//cout << cnt << " i\n";
mn = min(mn, cnt-fr+1 - 3*k);
}
signed main(){
cin >> n >> k;
cin >> s; s = '.'+s;
for(int i=n; i>=1; i--){
O[i] = O[i+1] + (s[i]=='O' ? 1 : 0);
I[i] = I[i+1] + (s[i]=='I' ? 1 : 0);
}
for(int i=1; i<=n; i++){
if(s[i] == 'J'){
vec.pb(i);
}
}
for(int i=k-1; i<vec.size(); i++){
f(vec[i], vec[i-k+1]);
}
cout << (mn>n ? -1 : mn) << '\n';
}
Compilation message (stderr)
ho_t2.cpp: In function 'int main()':
ho_t2.cpp:56: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]
56 | for(int i=k-1; i<vec.size(); i++){
| ~^~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |