Submission #702341

# Submission time Handle Problem Language Result Execution time Memory
702341 2023-02-23T15:28:39 Z Koful123 JJOOII 2 (JOI20_ho_t2) C++17
100 / 100
90 ms 41568 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
 
void solve(){
 
	int n,k;
	cin >> n >> k;
 
	int ans = 1e18; string s; cin >> s;
	vector<array<int,26>> cnt(n + 37);
	cnt[0][s[0] - 'A'] = 1;
	for(int i = 1; i < n; i++){
		for(int j = 0; j < 26; j++){
			cnt[i][j] = cnt[i-1][j];
		}
		cnt[i][s[i] - 'A']++;
	}
 
	auto check = [&](int i,int m,int ch){
		if(i < 0 || m < 0) return false;
		return (cnt[i][ch] - (m > 0 ? cnt[m-1][ch] : 0) >= k);
	};	
 
	for(int i = 0; i < n; i++){
		if(s[i] != 'I') continue;
		int l = 0,r = i;
		while(l < r){
			int m = (l + r + 1) / 2;
			if(check(i,m,'I'-'A')) l = m;
			else r = m - 1;
		}
		if(!check(i,l,'I'-'A')) continue;
		int pre = l - 1; r = l - 1; l = 0;
		while(l < r){
			int m = (l + r + 1) / 2;
			if(check(pre,m,'O'-'A')) l = m;
			else r = m - 1;	
		}
		if(!check(pre,l,'O'-'A')) continue;
		pre = l - 1; r = l - 1; l = 0;
		while(l < r){
			int m = (l + r + 1) / 2;
			if(check(pre,m,'J'-'A')) l = m;
			else r = m - 1;	
		}
		if(!check(pre,l,'J'-'A')) continue;
		ans = min(ans,i-l+1 - k*3);
	}
 
	cout << (ans == 1e18 ? -1 : ans) << endl;
}
 
signed main(){ 
 
	ios::sync_with_stdio(0);
	cin.tie(0);
 
	int t = 1;
//	cin >> t;
 
	while(t--)
		solve();
 	
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 320 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 320 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 852 KB Output is correct
16 Correct 1 ms 852 KB Output is correct
17 Correct 1 ms 852 KB Output is correct
18 Correct 1 ms 596 KB Output is correct
19 Correct 1 ms 852 KB Output is correct
20 Correct 1 ms 852 KB Output is correct
21 Correct 1 ms 852 KB Output is correct
22 Correct 1 ms 832 KB Output is correct
23 Correct 1 ms 596 KB Output is correct
24 Correct 1 ms 852 KB Output is correct
25 Correct 1 ms 852 KB Output is correct
26 Correct 1 ms 828 KB Output is correct
27 Correct 1 ms 956 KB Output is correct
28 Correct 1 ms 852 KB Output is correct
29 Correct 1 ms 852 KB Output is correct
30 Correct 1 ms 852 KB Output is correct
31 Correct 1 ms 596 KB Output is correct
32 Correct 1 ms 852 KB Output is correct
33 Correct 1 ms 856 KB Output is correct
34 Correct 1 ms 964 KB Output is correct
35 Correct 1 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 320 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 852 KB Output is correct
16 Correct 1 ms 852 KB Output is correct
17 Correct 1 ms 852 KB Output is correct
18 Correct 1 ms 596 KB Output is correct
19 Correct 1 ms 852 KB Output is correct
20 Correct 1 ms 852 KB Output is correct
21 Correct 1 ms 852 KB Output is correct
22 Correct 1 ms 832 KB Output is correct
23 Correct 1 ms 596 KB Output is correct
24 Correct 1 ms 852 KB Output is correct
25 Correct 1 ms 852 KB Output is correct
26 Correct 1 ms 828 KB Output is correct
27 Correct 1 ms 956 KB Output is correct
28 Correct 1 ms 852 KB Output is correct
29 Correct 1 ms 852 KB Output is correct
30 Correct 1 ms 852 KB Output is correct
31 Correct 1 ms 596 KB Output is correct
32 Correct 1 ms 852 KB Output is correct
33 Correct 1 ms 856 KB Output is correct
34 Correct 1 ms 964 KB Output is correct
35 Correct 1 ms 860 KB Output is correct
36 Correct 54 ms 38644 KB Output is correct
37 Correct 61 ms 41440 KB Output is correct
38 Correct 61 ms 41560 KB Output is correct
39 Correct 90 ms 41124 KB Output is correct
40 Correct 69 ms 41568 KB Output is correct
41 Correct 83 ms 41544 KB Output is correct
42 Correct 79 ms 41544 KB Output is correct
43 Correct 34 ms 25940 KB Output is correct
44 Correct 45 ms 32192 KB Output is correct
45 Correct 60 ms 41544 KB Output is correct
46 Correct 61 ms 41556 KB Output is correct
47 Correct 55 ms 41540 KB Output is correct
48 Correct 59 ms 41540 KB Output is correct
49 Correct 34 ms 27772 KB Output is correct
50 Correct 56 ms 41560 KB Output is correct
51 Correct 55 ms 41536 KB Output is correct
52 Correct 36 ms 39960 KB Output is correct
53 Correct 35 ms 41440 KB Output is correct
54 Correct 51 ms 41444 KB Output is correct
55 Correct 37 ms 41440 KB Output is correct
56 Correct 32 ms 41536 KB Output is correct