Submission #506162

# Submission time Handle Problem Language Result Execution time Memory
506162 2022-01-11T19:10:00 Z thomas_li JJOOII 2 (JOI20_ho_t2) C++17
100 / 100
43 ms 3192 KB
#include <bits/stdc++.h>
using namespace std;
const int MM = 2e5+5;
int n,k,psa[3][MM]; string s;
int f(char c){
	return (c == 'J' ? 0 : c == 'O' ? 1 : 2);
}
int next_k(int i, int j){
	if(i > n) return -1;
	int lo = i, hi = n;	
	while(lo < hi){
		int mid = (lo+hi)/2;
		if(psa[j][mid] - psa[j][i-1] >= k) hi = mid;
		else lo = mid+1;
	}
	if(psa[j][lo] - psa[j][i-1] < k) return -1;
	return lo;
}
int main(){
	cin >> n >> k >> s;
	s = ' ' + s;
	for(int i = 1; i <= n; i++){
		psa[0][i] += psa[0][i-1];
		psa[1][i] += psa[1][i-1];
		psa[2][i] += psa[2][i-1];
		psa[f(s[i])][i] += 1;
	}
	int ans = 1e9;
	for(int i = 1; i <= n; i++){
		int v = next_k(i,0),len = 0,p = i;
		if(v == -1) continue;	
		len += v - p+1;

		p = v+1;
		v = next_k(p,1);
		if(v == -1) continue;
		len += v - p+1;

		p = v+1;
		v = next_k(p,2);
		if(v == -1) continue;		
		len += v - p + 1;
		ans = min(ans,len - 3*k);
	}
	cout << (ans==1e9?-1:ans) << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 296 KB Output is correct
5 Correct 0 ms 300 KB Output is correct
6 Correct 1 ms 304 KB Output is correct
7 Correct 0 ms 296 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 292 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 296 KB Output is correct
5 Correct 0 ms 300 KB Output is correct
6 Correct 1 ms 304 KB Output is correct
7 Correct 0 ms 296 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 292 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 296 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 300 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 308 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 0 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 296 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 272 KB Output is correct
33 Correct 1 ms 280 KB Output is correct
34 Correct 1 ms 288 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 296 KB Output is correct
5 Correct 0 ms 300 KB Output is correct
6 Correct 1 ms 304 KB Output is correct
7 Correct 0 ms 296 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 292 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 296 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 300 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 308 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 0 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 296 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 272 KB Output is correct
33 Correct 1 ms 280 KB Output is correct
34 Correct 1 ms 288 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 30 ms 2840 KB Output is correct
37 Correct 32 ms 3100 KB Output is correct
38 Correct 32 ms 3068 KB Output is correct
39 Correct 43 ms 3096 KB Output is correct
40 Correct 30 ms 3072 KB Output is correct
41 Correct 34 ms 3072 KB Output is correct
42 Correct 39 ms 3096 KB Output is correct
43 Correct 16 ms 2016 KB Output is correct
44 Correct 20 ms 2492 KB Output is correct
45 Correct 30 ms 3080 KB Output is correct
46 Correct 25 ms 3088 KB Output is correct
47 Correct 26 ms 3088 KB Output is correct
48 Correct 26 ms 3064 KB Output is correct
49 Correct 18 ms 2244 KB Output is correct
50 Correct 28 ms 3068 KB Output is correct
51 Correct 31 ms 3092 KB Output is correct
52 Correct 17 ms 2976 KB Output is correct
53 Correct 17 ms 3076 KB Output is correct
54 Correct 20 ms 3092 KB Output is correct
55 Correct 17 ms 3080 KB Output is correct
56 Correct 15 ms 3192 KB Output is correct