# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
202627 | SamAnd | JJOOII 2 (JOI20_ho_t2) | C++17 | 43 ms | 2940 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;
const int N = 200005;
int n, k;
char a[N];
int p[N][3];
int byn(int x, int j)
{
int l = x, r = n;
int ans = n + 1;
while (l <= r)
{
int m = (l + r) / 2;
if (p[m][j] - p[x - 1][j] >= k)
{
ans = m;
r = m - 1;
}
else
l = m + 1;
}
return ans;
}
int main()
{
scanf("%d%d", &n, &k);
scanf(" %s", (a + 1));
for (int i = 1; i <= n; ++i)
{
if (a[i] == 'J')
a[i] = 0;
else if (a[i] == 'O')
a[i] = 1;
else
a[i] = 2;
}
for (int i = 1; i <= n; ++i)
{
for (int j = 0; j < 3; ++j)
p[i][j] = p[i - 1][j];
p[i][a[i]]++;
}
int ans = N;
for (int i = 1; i <= n; ++i)
{
int x = byn(i, 0);
x = byn(x + 1, 1);
x = byn(x + 1, 2);
if (x <= n)
ans = min(ans, x - i + 1 - 3 * k);
}
if (ans == N)
printf("-1\n");
else
printf("%d\n", 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... |