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;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
const int maxn = 4e5 + 10;
int n, k;
int J[maxn], O[maxn], I[maxn];
int nex(int t, int par[]){
int lo = t - 1, hi = n;
while (hi - lo > 1){
int mid = (lo + hi) >> 1;
if (par[mid + 1] - par[t] >= k)
hi = mid;
else
lo = mid;
}
return hi;
}
int main(){
ios_base::sync_with_stdio(false);
string s;
cin >> n >> k;
cin >> s;
for (int i = 0; i < n; i++){
J[i + 1] = J[i] + (s[i] == 'J');
O[i + 1] = O[i] + (s[i] == 'O');
I[i + 1] = I[i] + (s[i] == 'I');
}
int answer = -1;
for (int i = 0; i < n; i++){
int t = nex(i, J);
t = nex(t, O);
t = nex(t, I);
if (t >= n)
break;
if (answer == -1 or answer > (t - i + 1 - 3 * k))
answer = t - i + 1 - 3 * k;
}
cout << answer << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |