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;
using ll = long long;
#define sz(v) (int)(v).size()
#define all(v) (v).begin(), (v).end()
int f(char c) {
return (c == 'J' ? 0 : 1 + (c == 'I'));
}
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int n, k;
string s;
cin >> n >> k >> s;
vector<int> v[3];
for (int i = 0; i < n; i++)
v[f(s[i])].push_back(i);
int mn = n;
for (int i = 0; i < n; i++) {
if (s[i] != 'J') continue;
int x = i - 1;
for (int j = 0; j < 3; j++) {
x = upper_bound(all(v[j]), x) - v[j].begin();
if (x + k > sz(v[j])) {
x = n; break;
}
x = v[j][x + k - 1];
}
if (x == n) break;
mn = min(mn, x - i);
}
cout << (mn == n ? -1 : mn + 1 - 3 * k);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |