# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
203224 | staniewzki | JJOOII 2 (JOI20_ho_t2) | C++14 | 0 ms | 0 KiB |
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;
int main() {
int n, k;
string str;
cin >> n >> k >> str;
vector<vector<int>> pos(3);
vector<int> last(4, -1e9);
map<char, int> id = {{'J', 0}, {'O', 1}, {'I', 2}};
int ans = 1e9;
for(int i = 0; i < n; i++) {
last[0] = i;
int x = id[str[i]];
pos[x].emplace_back(last[x]);
if(size(pos[x]) >= k)
last[x + 1] = pos[x][size(pos[x]) - k];
ans = min(ans, i - last[3] + 1 - 3 * k);
}
if(ans > n) ans = -1;
cout << ans << "\n";
}