Submission #847657

# Submission time Handle Problem Language Result Execution time Memory
847657 2023-09-10T06:11:17 Z willychan JJOOII 2 (JOI20_ho_t2) C++14
100 / 100
20 ms 3420 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include<bits/extc++.h>
//__gnu_pbds




int main(){
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int n,k;cin>>n>>k;
	vector<int> J(n+1,0);
	vector<int> O(n+1,0);
	vector<int> I(n+1,0);
	string s;cin>>s;	
	for(int i=1;i<=n;i++){
		J[i]=J[i-1];
		O[i]=O[i-1];
		I[i]=I[i-1];
		if(s[i-1]=='J') J[i]++;
		if(s[i-1]=='O') O[i]++;
		if(s[i-1]=='I') I[i]++;
	}
	int ans = 1e9;
	for(int i=1;i<=n;i++){
		if(s[i-1]!='I') continue;
		int l = -1;int r = i;
		int t = i;
		while(r-l>1){
			int mid = (l+r)/2;
			if(I[t]-I[mid]>=k) l = mid;
			else r = mid;
		}
		r = l;l = -1;
		if(r<=0) continue;
		t = r;
		while(r-l>1){
			int mid = (l+r)/2;
			if(O[t]-O[mid]>=k) l = mid;
			else r = mid;
		}
		r = l;l = -1;
		if(r<=0) continue;
		t = r;
		while(r-l>1){
			int mid = (l+r)/2;
			if(J[t]-J[mid]>=k) l=mid;
			else r = mid;
		}
		if(l>=0){
			ans = min(ans,i-l-3*k);
		}
	}
	if(ans>=1e7) cout<<-1<<"\n";
	else cout<<ans<<"\n";

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 452 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 452 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 452 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 452 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 456 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 604 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 452 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 452 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 456 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 18 ms 3164 KB Output is correct
37 Correct 20 ms 3304 KB Output is correct
38 Correct 19 ms 3304 KB Output is correct
39 Correct 17 ms 3304 KB Output is correct
40 Correct 14 ms 3304 KB Output is correct
41 Correct 17 ms 3304 KB Output is correct
42 Correct 19 ms 3304 KB Output is correct
43 Correct 8 ms 2136 KB Output is correct
44 Correct 10 ms 2904 KB Output is correct
45 Correct 13 ms 3300 KB Output is correct
46 Correct 13 ms 3300 KB Output is correct
47 Correct 13 ms 3304 KB Output is correct
48 Correct 13 ms 3304 KB Output is correct
49 Correct 8 ms 2396 KB Output is correct
50 Correct 13 ms 3304 KB Output is correct
51 Correct 14 ms 3420 KB Output is correct
52 Correct 8 ms 3164 KB Output is correct
53 Correct 8 ms 3280 KB Output is correct
54 Correct 19 ms 3340 KB Output is correct
55 Correct 11 ms 3304 KB Output is correct
56 Correct 7 ms 3304 KB Output is correct