이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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){
if (occs[i][nVals] - occs[i][cur] < K) ok = false;
cur = lower_bound(occs[i], occs[i] + nVals + 1, occs[i][cur] + K) - occs[i];
}
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... |