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 sz(x) (int)x.size()
#define chmin(x, v) x = min(x, v)
#define chmax(x, v) x = max(x, v)
#define all(x) x.begin(), x.end()
#define pb push_back
#define pii pair<int, int>
#define deb first
#define fin second
#define int long long
using namespace std;
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int nVals, K; cin >> nVals >> K;
string chaine; cin >> chaine;
int occs[3][nVals + 1];
for (int i = 0; i < 3; ++i)
occs[i][0] = 0;
for (int ind = 0; ind < nVals; ++ind){
for (int i = 0; i < 3; ++i)
occs[i][ind + 1] = occs[i][ind];
if (chaine[ind] == 'J')
occs[0][ind + 1]++;
else if (chaine[ind] == 'O')
occs[1][ind + 1]++;
else
occs[2][ind + 1]++;
}
int mini = nVals + 5;
for (int deb = 1; deb < nVals; ++deb){
int cur = deb - 1;
bool ok = true;
for (int i = 0; i < 3; ++i){
int bef = cur;
cur = lower_bound(occs[i], occs[i] + nVals + 1, occs[i][cur] + K) - occs[i];
ok &= (occs[i][cur] - occs[i][bef] >= K);
}
if (ok) {
//cout << deb << " " << cur << endl;
chmin(mini, cur - deb + 1);
}
}
if (mini <= nVals)
cout << mini - 3 * K << endl;
else
cout << -1 << endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |