Submission #469349

# Submission time Handle Problem Language Result Execution time Memory
469349 2021-08-31T14:34:03 Z Drew_ JJOOII 2 (JOI20_ho_t2) C++17
100 / 100
321 ms 3052 KB
#include <bits/stdc++.h>
using namespace std;

constexpr int MAX = 2e5 + 69;
constexpr int inf = 1e9 + 69;

int n, k;
char s[MAX];
int bit[3][MAX];

inline void add(int y, int x, int val)
{
	for (int i = x; i < MAX; i += (i & -i))
		bit[y][i] += val;
}

inline int sum(int y, int x)
{
	int res = 0;
	for (int i = x; i > 0; i -= (i & -i))
		res += bit[y][i];
	return res;
}

int main()
{
	ios :: sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	cin >> n >> k >> (s+1);

	for (int i = 1; i <= n; ++i)
	{
		if (s[i] == 'J') add(0, i, 1);
		if (s[i] == 'O') add(1, i, 1);
		if (s[i] == 'I') add(2, i, 1);
	}

	int res = inf;
	for (int i = 0; i <= n; ++i)
	{
		int x = i+1;
		for (int y = 0; y < 3; ++y)
		{
			int l = x, r = n+1;
			while (l < r)
			{
				int mid = (l + r) >> 1;
				if (sum(y, mid) - sum(y, x-1) < k) l = mid + 1;
				else r = mid;
			}
			x = l;
		}
		if (x == n+1) break;

		res = min(res, x-i - 3*k);
	}
	cout << (res == inf ? -1 : res) << '\n';

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 320 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 320 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 320 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 320 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
16 Correct 4 ms 332 KB Output is correct
17 Correct 3 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 3 ms 332 KB Output is correct
20 Correct 3 ms 332 KB Output is correct
21 Correct 2 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 320 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 320 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 2 ms 332 KB Output is correct
16 Correct 4 ms 332 KB Output is correct
17 Correct 3 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 3 ms 332 KB Output is correct
20 Correct 3 ms 332 KB Output is correct
21 Correct 2 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 262 ms 2892 KB Output is correct
37 Correct 294 ms 3040 KB Output is correct
38 Correct 287 ms 3020 KB Output is correct
39 Correct 275 ms 3020 KB Output is correct
40 Correct 76 ms 3032 KB Output is correct
41 Correct 226 ms 3052 KB Output is correct
42 Correct 321 ms 3036 KB Output is correct
43 Correct 6 ms 1996 KB Output is correct
44 Correct 7 ms 2380 KB Output is correct
45 Correct 7 ms 3020 KB Output is correct
46 Correct 8 ms 3020 KB Output is correct
47 Correct 7 ms 3020 KB Output is correct
48 Correct 7 ms 3020 KB Output is correct
49 Correct 5 ms 2124 KB Output is correct
50 Correct 7 ms 3020 KB Output is correct
51 Correct 7 ms 3020 KB Output is correct
52 Correct 7 ms 2876 KB Output is correct
53 Correct 7 ms 3020 KB Output is correct
54 Correct 98 ms 1524 KB Output is correct
55 Correct 44 ms 1484 KB Output is correct
56 Correct 5 ms 1484 KB Output is correct