# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
203122 | ZwariowanyMarcin | JJOOII 2 (JOI20_ho_t2) | C++14 | 13 ms | 3436 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>
#define LL long long
#define pb push_back
#define mp make_pair
#define ss(x) (int) x.size()
#define fi first
#define se second
#define cat(x) cerr << #x << " = " << x << endl
#define rep(i, j, n) for (int i = j; i <= n; ++i)
#define per(i, j, n) for (int i = n; j <= i; --i)
using namespace std;
const int nax = 2e5 + 111;
const int INF = 1e9 + 11;
int n, k;
char s[nax];
vector <int> v[3];
int J[nax];
int I[nax];
int main() {
scanf ("%d%d", &n, &k);
scanf ("%s", s + 1);
int a = 0, b = 0;
rep(i, 1, n) {
if (s[i] == 'J') v[0].pb(i), ++a;
if (s[i] == 'O') v[1].pb(i);
if (s[i] == 'I') v[2].pb(i), ++b;
J[i] = a;
I[i] = b;
}
int best = INF;
for (int i = 0; i + k - 1 < ss(v[1]); ++i) {
int x = v[1][i];
int y = v[1][i + k - 1];
int l = (J[x] - k >= 0 ? v[0][J[x] - k] : -1);
int r = (I[y] + k - 1 < ss(v[2]) ? v[2][I[y] + k - 1] : -1);
if (l == -1 || r == -1) continue;
//printf ("%d %d %d %d\n", i, l, r, x);
best = min(best, r - l + 1);
}
if (best == INF) printf ("-1\n");
else printf ("%d\n", best - 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... |