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(pos[x].size() >= k)
last[x + 1] = pos[x][pos[x].size() - k];
ans = min(ans, i - last[3] + 1 - 3 * k);
}
if(ans > n) ans = -1;
cout << ans << "\n";
}
Compilation message (stderr)
ho_t2.cpp: In function 'int main()':
ho_t2.cpp:18:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(pos[x].size() >= 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... |