Submission #702265

# Submission time Handle Problem Language Result Execution time Memory
702265 2023-02-23T12:16:24 Z Koful123 JJOOII 2 (JOI20_ho_t2) C++17
1 / 100
1 ms 852 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 = 1e9; string s; cin >> s;
	vector<array<int,26>> cnt(n);
	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){
		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 == 1e9 ? -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 1 ms 212 KB Output is correct
4 Correct 1 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 1 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 1 ms 212 KB Output is correct
4 Correct 1 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 1 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 596 KB Output is correct
16 Correct 1 ms 596 KB Output is correct
17 Correct 1 ms 596 KB Output is correct
18 Runtime error 1 ms 852 KB Execution killed with signal 11
19 Halted 0 ms 0 KB -
# 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 1 ms 212 KB Output is correct
4 Correct 1 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 1 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 596 KB Output is correct
16 Correct 1 ms 596 KB Output is correct
17 Correct 1 ms 596 KB Output is correct
18 Runtime error 1 ms 852 KB Execution killed with signal 11
19 Halted 0 ms 0 KB -