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;
cin >> n >> k;
string s;
cin >> s;
vector<int> jpos, opos, ipos;
for (int l = 0; l < n; l++) {
if (s[l] == 'J') jpos.push_back(l);
if (s[l] == 'O') opos.push_back(l);
if (s[l] == 'I') ipos.push_back(l);
}
int ans = INT_MAX;
for (int j = 0; j <= jpos.size()-k; j++) {
int lb = jpos[j+k-1];
auto it = lower_bound(opos.begin(), opos.end(), lb);
if (it == opos.end()) break;
int idx = it-opos.begin();
lb = opos[idx+k-1];
it = lower_bound(ipos.begin(), ipos.end(), lb);
if (it == ipos.end()) break;
idx = it-ipos.begin();
int l = jpos[j], r = ipos[idx+k-1];
ans = min(ans, (r-l+1)-(3*k));
}
if (ans == INT_MAX) ans = -1;
cout << ans << '\n';
return 0;
}
Compilation message (stderr)
ho_t2.cpp: In function 'int main()':
ho_t2.cpp:16:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
16 | for (int j = 0; j <= jpos.size()-k; j++) {
| ~~^~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |