Submission #365268

# Submission time Handle Problem Language Result Execution time Memory
365268 2021-02-11T10:59:42 Z Meloric JJOOII 2 (JOI20_ho_t2) C++14
100 / 100
34 ms 5624 KB
#include <bits/stdc++.h>
#define pb push_back
#define int int64_t
#define pii pair<int, int>
#define X first
#define Y second
#define all(x) (x).begin(),(x).end()

using namespace std;

const int inf  = 1e18;

void solve(){
	int n, k; cin >> n >> k;
	string A; cin >> A;
	vector<int> J(n+1), O(n+1), I(n+1);
	for(int i = 0; i< n; i++){
		if(A[i] == 'J')J[i+1]++;
		if(A[i] == 'O')O[i+1]++;
		if(A[i] == 'I')I[i+1]++;
	}
	for(int i = 1; i< n+1; i++){
		J[i]+=J[i-1];
		O[i]+=O[i-1];
		I[i]+=I[i-1];
	}
	int ans = -1;
	for(int i = 0; i< n; i++){
		int p1 = lower_bound(all(J), k+J[i])-J.begin();
		if(p1 == n+1)break;
		int p2 = lower_bound(all(O), k+O[p1])-O.begin();
		if(p2 == n+1)break;
		int p3 = lower_bound(all(I), k+I[p2])-I.begin();
		if(p3 == n+1)break;
		ans = min((ans == -1) ? (int64_t)1e9 : ans, p3-i-3*k);
	}
	cout << ans;
}
	
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int t = 1;
	//cin >> t;
	while(t--)solve();
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 0 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 0 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 444 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 0 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 444 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 1 ms 364 KB Output is correct
30 Correct 1 ms 364 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 32 ms 5368 KB Output is correct
37 Correct 34 ms 5496 KB Output is correct
38 Correct 34 ms 5496 KB Output is correct
39 Correct 27 ms 5496 KB Output is correct
40 Correct 12 ms 5496 KB Output is correct
41 Correct 23 ms 5496 KB Output is correct
42 Correct 32 ms 5624 KB Output is correct
43 Correct 5 ms 3564 KB Output is correct
44 Correct 5 ms 4344 KB Output is correct
45 Correct 7 ms 5496 KB Output is correct
46 Correct 7 ms 5496 KB Output is correct
47 Correct 7 ms 5496 KB Output is correct
48 Correct 7 ms 5496 KB Output is correct
49 Correct 5 ms 3832 KB Output is correct
50 Correct 7 ms 5496 KB Output is correct
51 Correct 7 ms 5496 KB Output is correct
52 Correct 6 ms 5368 KB Output is correct
53 Correct 7 ms 5496 KB Output is correct
54 Correct 13 ms 5496 KB Output is correct
55 Correct 8 ms 5496 KB Output is correct
56 Correct 5 ms 5496 KB Output is correct