# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1031743 | juicy | JJOOII 2 (JOI20_ho_t2) | C++17 | 1 ms | 604 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;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
const int N = 2e5 + 5;
int n, k;
string s;
int jump[N];
array<int, 3> nxt[N];
int conv(char c) {
return c == 'J' ? 0 : (c == 'O' ? 1 : 2);
}
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> n >> k >> s;
array<int, 3> lst = {n + 1, n + 1, n + 1};
vector<vector<int>> pos(3);
for (int i = n; i >= 1; --i) {
nxt[i] = lst;
int c = conv(s[i - 1]);
lst[c] = i;
pos[c].push_back(i);
if (pos[c].size() >= k) {
jump[i] = pos[c].end()[-k];
} else {
jump[i] = n + 1;
}
}
int ans = 1e9;
for (int i = 0; i < N; ++i) {
if (s[i] == 'J') {
int p = i + 1;
for (int j = 0; j < 3; ++j) {
p = jump[p];
if (p == n + 1) {
break;
}
if (j + 1 < 3) {
p = nxt[p][j + 1];
}
if (p == n + 1) {
break;
}
}
if (p != n + 1) {
ans = min(ans, n - 3 * k - i - n + p);
}
}
}
cout << (ans == 1e9 ? -1 : ans);
return 0;
}
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... |