Submission #237165

# Submission time Handle Problem Language Result Execution time Memory
237165 2020-06-05T02:42:02 Z wwdd JJOOII 2 (JOI20_ho_t2) C++14
100 / 100
33 ms 3212 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INFL = 1e18;
const int MN = 200100;
int pr[3][MN];
int main() {
	ios::sync_with_stdio(0);cin.tie(0);
	ll n,k;
	cin >> n >> k;
	string s;
	cin >> s;
	pr[0][0] = pr[0][1] = pr[0][2] = 0;
	for(int i=0;i<n;i++) {
		for(int j=0;j<3;j++) {
			pr[j][i+1] = pr[j][i];
		}
		if(s[i] == 'J') {
			pr[0][i+1]++;
		} else if(s[i] == 'O') {
			pr[1][i+1]++;
		} else {
			pr[2][i+1]++;
		}
	}
	ll res = -1;
	for(int i=0;i<n;i++) {
		int u = i;
		for(int j=0;j<3;j++) {
			u = lower_bound(pr[j]+u,pr[j]+n+1,pr[j][u]+k)-pr[j];
		}
		if(u <= n) {
			res = max(res,i+n-u);
		}
	}
	if(res == -1) {
		cout << -1 << '\n';
	} else {
		ll ans = n-3*k-res;
		cout << ans << '\n';
	}
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 512 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 512 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 5 ms 512 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 5 ms 384 KB Output is correct
34 Correct 5 ms 384 KB Output is correct
35 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 4 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 512 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 4 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 5 ms 512 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 5 ms 384 KB Output is correct
34 Correct 5 ms 384 KB Output is correct
35 Correct 5 ms 384 KB Output is correct
36 Correct 23 ms 3084 KB Output is correct
37 Correct 25 ms 3212 KB Output is correct
38 Correct 25 ms 3212 KB Output is correct
39 Correct 33 ms 3212 KB Output is correct
40 Correct 25 ms 3212 KB Output is correct
41 Correct 31 ms 3212 KB Output is correct
42 Correct 33 ms 3212 KB Output is correct
43 Correct 15 ms 2176 KB Output is correct
44 Correct 19 ms 2572 KB Output is correct
45 Correct 23 ms 3212 KB Output is correct
46 Correct 23 ms 3212 KB Output is correct
47 Correct 23 ms 3212 KB Output is correct
48 Correct 23 ms 3212 KB Output is correct
49 Correct 17 ms 2444 KB Output is correct
50 Correct 24 ms 3212 KB Output is correct
51 Correct 23 ms 3212 KB Output is correct
52 Correct 15 ms 3084 KB Output is correct
53 Correct 15 ms 3212 KB Output is correct
54 Correct 17 ms 3212 KB Output is correct
55 Correct 15 ms 3212 KB Output is correct
56 Correct 13 ms 3212 KB Output is correct