| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1294343 | harryleee | JJOOII 2 (JOI20_ho_t2) | C++20 | 5 ms | 1308 KiB |
#include <bits/stdc++.h>
using namespace std;
#define NAME "A"
#define ll long long
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define MASK(x) (1ll << (x))
#define BIT(x, i) (((x) >> (i)) & 1)
const int N = 2e5 + 5;
const int inf = 1e9;
int n, k;
string s;
deque<int> J, O, I;
void input() {
cin >> n >> k >> s;
s = " " + s;
}
void solve() {
int ans = inf;
for (int i = 1; i <= n; i++) {
if (s[i] == 'J') J.pb(i);
else if (s[i] == 'O') O.pb(i);
else I.pb(i);
}
while ((int)J.size() >= k) {
while (O.size() && O.front() <= J[k - 1]) {
O.pop_front();
}
if ((int)O.size() < k) break;
while (I.size() && I.front() <= O[k - 1]) {
I.pop_front();
}
if ((int)I.size() < k) break;
ans = min(ans, I[k - 1] - J[0] - 3 * k + 1);
J.pop_front();
}
if (ans == inf) {
ans = -1;
}
cout << ans;
}
signed main() {
if (fopen(NAME".INP", "r")) {
freopen(NAME".INP", "r", stdin);
freopen(NAME".OUT", "w", stdout);
}
cin.tie(0)->sync_with_stdio(0);
input();
solve();
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... | ||||
