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 F first
#define S second
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " " << (x) << endl;
#define V vector
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int k, n;
string s;
cin >> n >> k >> s;
int mx = -1;
vi js, os, is;
for(int i = 0; i < n; i++) {
if(s[i] == 'J') js.PB(i);
else if(s[i] == 'O') os.PB(i);
else is.PB(i);
}
for(int i = 0; i + k - 1 < (int)js.size(); i++) {
int j = js[i + k - 1];
j = lower_bound(ALL(os), j) - os.begin();
if(j + k - 1 >= (int)os.size()) break;
j = os[j + k - 1];
j = lower_bound(ALL(is), j) - is.begin();
if(j + k - 1 >= (int)is.size()) break;
j = is[j + k - 1];
mx = max(mx, js[i] + n - 1 - j);
}
if(mx == -1) cout << -1 << endl;
else {
cout << n-mx-3*k << endl;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |