Submission #1027120

# Submission time Handle Problem Language Result Execution time Memory
1027120 2024-07-18T22:31:53 Z racsosabe JJOOII 2 (JOI20_ho_t2) C++14
100 / 100
13 ms 3560 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 200000 + 5;
const string JOI = "JOI";

int id(char c) {
	for(int i = 0; i < JOI.size(); i++) {
		if(JOI[i] == c) return i;
	}
	return -1;
}

int n;
int k;
string s;
int prefix[3][N];

int get_first_k(int id, int l) {
	int lo = l, hi = n + 1;
	while(lo < hi) {
		int mi = lo + (hi - lo) / 2;
		if(prefix[id][mi] - prefix[id][l - 1] < k) lo = mi + 1;
		else hi = mi;
	}
	return lo;
}

int solve(int at) {
	int l = at;
	for(int i = 0; i < 3; i++) {
		int to = get_first_k(i, at);
		if(to > n) return -1;
		at = to;
	}
	return at - l + 1 - 3 * k;
}

int main() {
	cin.tie(0) -> sync_with_stdio(false);
	cin >> n >> k >> s;
	for(int i = 1; i <= n; i++) {
		for(int j = 0; j < 3; j++) prefix[j][i] = prefix[j][i - 1];
		prefix[id(s[i - 1])][i] += 1;
	}
	int res = -1;
	for(int i = 1; i <= n; i++) {
		if(s[i - 1] != 'J') continue;
		int cur = solve(i);
		if(cur == -1) continue;
		if(res == -1 or res > cur) res = cur;
	}
	cout << res << endl;
	return 0;
}

Compilation message

ho_t2.cpp: In function 'int id(char)':
ho_t2.cpp:8:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 |  for(int i = 0; i < JOI.size(); i++) {
      |                 ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 464 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 600 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 464 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 600 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 464 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 600 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 464 KB Output is correct
36 Correct 9 ms 3048 KB Output is correct
37 Correct 9 ms 3296 KB Output is correct
38 Correct 9 ms 3096 KB Output is correct
39 Correct 13 ms 3304 KB Output is correct
40 Correct 10 ms 3304 KB Output is correct
41 Correct 12 ms 3304 KB Output is correct
42 Correct 13 ms 3304 KB Output is correct
43 Correct 6 ms 2292 KB Output is correct
44 Correct 7 ms 2536 KB Output is correct
45 Correct 9 ms 3304 KB Output is correct
46 Correct 9 ms 3332 KB Output is correct
47 Correct 9 ms 3304 KB Output is correct
48 Correct 9 ms 3560 KB Output is correct
49 Correct 6 ms 2280 KB Output is correct
50 Correct 9 ms 3336 KB Output is correct
51 Correct 9 ms 3556 KB Output is correct
52 Correct 6 ms 3240 KB Output is correct
53 Correct 7 ms 3304 KB Output is correct
54 Correct 8 ms 3304 KB Output is correct
55 Correct 5 ms 3304 KB Output is correct
56 Correct 4 ms 3304 KB Output is correct