# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
995261 | gmroh06 | JJOOII 2 (JOI20_ho_t2) | C++14 | 6 ms | 5028 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;
using ll = long long;
using pll = pair<ll, ll>;
inline void fastio() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
}
const ll INF = 1e16;
ll n, k, ans = INF;
vector<ll> a, b, v;
string s;
int main() {
fastio();
cin >> n >> k >> s;
a.resize(n + 2);
b.resize(n + 2);
a[0] = b[n + 1] = -1;
for (ll i = 1; i <= n; i++) {
if (s[i - 1] == 'J') {
v.emplace_back(i);
}
if (v.size() < k) {
a[i] = -1;
} else {
a[i] = *(v.end() - k);
}
}
v.clear();
for (ll i = n; i > 0; i--) {
if (s[i - 1] == 'I') {
v.emplace_back(i);
}
if (v.size() < k) {
b[i] = -1;
} else {
b[i] = *(v.end() - k);
}
}
v.clear();
for (ll i = 1; i <= n; i++) {
if (s[i - 1] == 'O') {
v.emplace_back(i);
}
if (v.size() < k) {
continue;
}
ll l = a[*(v.end() - k) - 1], r = b[i + 1];
if (l > -1 and r > -1) {
ans = min(ans, r - l + 1);
}
}
cout << (ans == INF ? -1 : ans - 3 * k);
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... |