# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
973871 | Pekiban | JJOOII 2 (JOI20_ho_t2) | C++17 | 23 ms | 2004 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 f(char c) {
return c == 'J' ? 2 : c == 'I';
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, k;
cin >> n >> k;
vector<int> v[3];
for (int i = 0; i < n; ++i) {
char c;
cin >> c;
v[f(c)].push_back(i);
}
auto fnd = [&](int x, char c) {
return lower_bound(v[f(c)].begin(), v[f(c)].end(), x) - v[f(c)].begin();
};
int ans = 1e9;
for (int i = 0; i < n; ++i) {
int x = fnd(i, 'J');
if (x + k - 1 >= v[f('J')].size()) break;
int y = fnd(v[f('J')][x + k - 1], f('O'));
if (y + k - 1 >= v[f('O')].size()) break;
int z = fnd(v[f('O')][y + k - 1], 'I');
if (z + k - 1 >= v[f('I')].size()) break;
ans = min(ans, v[f('I')][z + k - 1] - i - 3*k + 1);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |