Submission #702342

# Submission time Handle Problem Language Result Execution time Memory
702342 2023-02-23T15:30:14 Z Koful123 JJOOII 2 (JOI20_ho_t2) C++17
100 / 100
87 ms 41400 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(pre == -1 || !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(pre == -1 || !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 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 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 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 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 704 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 852 KB Output is correct
23 Correct 0 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 852 KB Output is correct
27 Correct 1 ms 852 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 852 KB Output is correct
34 Correct 1 ms 852 KB Output is correct
35 Correct 1 ms 852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 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 704 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 852 KB Output is correct
23 Correct 0 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 852 KB Output is correct
27 Correct 1 ms 852 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 852 KB Output is correct
34 Correct 1 ms 852 KB Output is correct
35 Correct 1 ms 852 KB Output is correct
36 Correct 59 ms 38420 KB Output is correct
37 Correct 57 ms 41252 KB Output is correct
38 Correct 59 ms 41312 KB Output is correct
39 Correct 84 ms 40928 KB Output is correct
40 Correct 65 ms 41312 KB Output is correct
41 Correct 87 ms 41400 KB Output is correct
42 Correct 73 ms 41312 KB Output is correct
43 Correct 32 ms 25812 KB Output is correct
44 Correct 43 ms 32136 KB Output is correct
45 Correct 55 ms 41308 KB Output is correct
46 Correct 56 ms 41352 KB Output is correct
47 Correct 55 ms 41312 KB Output is correct
48 Correct 59 ms 41348 KB Output is correct
49 Correct 34 ms 27616 KB Output is correct
50 Correct 55 ms 41304 KB Output is correct
51 Correct 55 ms 41236 KB Output is correct
52 Correct 36 ms 39732 KB Output is correct
53 Correct 34 ms 41312 KB Output is correct
54 Correct 48 ms 41312 KB Output is correct
55 Correct 41 ms 41312 KB Output is correct
56 Correct 28 ms 41312 KB Output is correct