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>
#ifdef _DEBUG
#define ls(x) << (x) << ", "
#define lv(x) << #x << ": " << flush << (x) << ", "
#define pr(x) cout << "Line: " << __LINE__ << ", " x << endl;
#else
#define ls(x)
#define lv(x)
#define pr(x) ;
#endif
using namespace std;
typedef unsigned int uint;
constexpr char J = 'J';
constexpr char O = 'O';
constexpr char I = 'I';
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
uint n, k;
cin >> n >> k;
string a;
cin >> a;
vector<uint> o(n), j(n), i(n);
uint o_size = 0, i_size = 0, j_size = 0;
for (uint it = 0; it < n; it++) {
if (a[it] == J) {
j[j_size] = it;
j_size++;
} else if (a[it] == O) {
o[o_size] = it;
o_size++;
} else if (a[it] == I) {
i[i_size] = it;
i_size++;
}
}
uint num_o = 0, result = 1e9;
for (uint it = 0; it < n; it++) {
pr(lv(it) lv(a[it]) lv(a[it] == O))
if (a[it] != O) continue;
pr()
num_o++;
vector<uint>::iterator i_pos = lower_bound(i.begin(), i.begin() + i_size, it);
if (i_pos == i.begin() + i_size) {
pr(ls("not found"))
continue;
}
int i_first = i.begin() - i_pos + k - 1;
int o_last = o[num_o + k - 1];
vector<uint>::iterator j_last_pos = upper_bound(j.begin(), j.begin() + j_size, o_last);
if (j_last_pos == i.begin() + j_size) {
pr(ls("not found"))
continue;
}
int j_last = *j_last_pos;
uint cost = j_last - i_first + 1 - 3*k;
pr(lv(num_o) lv(i_first) lv(o_last) lv(j_last))
result = min(result, cost);
}
if (result == 1e9) {
result = 0;
}
cout << result << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |