Submission #202949

# Submission time Handle Problem Language Result Execution time Memory
202949 2020-02-18T18:49:13 Z mraron JJOOII 2 (JOI20_ho_t2) C++14
100 / 100
82 ms 2952 KB
#include<bits/stdc++.h>
using namespace std;
int cnt[3][200001];
int n,k;
int until(int from, int typ) {
	int res=-1;
	for(int i=18;i>=0;i--) {
		int akt=res+(1<<i);
		if(from+akt>=n) continue ;
		if(cnt[typ][from+akt]-(from?cnt[typ][from-1]:0)<k) res=akt;
	}
	if(from+res+1!=n) return from+res+1;
	return -1;
}
int main() {
	string t;
	cin>>n>>k;
	cin>>t;
	for(int i=0;i<n;++i) {
		if(t[i]=='J') cnt[0][i]++;
		else if(t[i]=='O') cnt[1][i]++;
		else cnt[2][i]++;
	}
	
	for(int j=0;j<3;++j) for(int i=1;i<n;++i) cnt[j][i]+=cnt[j][i-1];
	int ans=1e9;
	for(int i=0;i<n;++i) {
		int jig=until(i,0);
		
		if(jig!=-1) {
			int oig=until(jig,1);
			if(oig!=-1) {
				int iig=until(oig,2);
				if(iig!=-1) {
					ans=min(ans, iig-i+1-3*k);
				}
			}
		}
	}
	if(ans==1e9) cout<<-1;
	else cout<<ans;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
9 Correct 4 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 256 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
9 Correct 4 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 256 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 6 ms 376 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 6 ms 376 KB Output is correct
20 Correct 6 ms 376 KB Output is correct
21 Correct 6 ms 380 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 5 ms 376 KB Output is correct
24 Correct 7 ms 376 KB Output is correct
25 Correct 5 ms 380 KB Output is correct
26 Correct 5 ms 376 KB Output is correct
27 Correct 5 ms 376 KB Output is correct
28 Correct 5 ms 380 KB Output is correct
29 Correct 5 ms 376 KB Output is correct
30 Correct 5 ms 376 KB Output is correct
31 Correct 5 ms 376 KB Output is correct
32 Correct 5 ms 376 KB Output is correct
33 Correct 5 ms 376 KB Output is correct
34 Correct 5 ms 376 KB Output is correct
35 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 256 KB Output is correct
9 Correct 4 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 256 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 6 ms 376 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 6 ms 376 KB Output is correct
20 Correct 6 ms 376 KB Output is correct
21 Correct 6 ms 380 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 5 ms 376 KB Output is correct
24 Correct 7 ms 376 KB Output is correct
25 Correct 5 ms 380 KB Output is correct
26 Correct 5 ms 376 KB Output is correct
27 Correct 5 ms 376 KB Output is correct
28 Correct 5 ms 380 KB Output is correct
29 Correct 5 ms 376 KB Output is correct
30 Correct 5 ms 376 KB Output is correct
31 Correct 5 ms 376 KB Output is correct
32 Correct 5 ms 376 KB Output is correct
33 Correct 5 ms 376 KB Output is correct
34 Correct 5 ms 376 KB Output is correct
35 Correct 5 ms 376 KB Output is correct
36 Correct 75 ms 2824 KB Output is correct
37 Correct 82 ms 2952 KB Output is correct
38 Correct 79 ms 2952 KB Output is correct
39 Correct 71 ms 2952 KB Output is correct
40 Correct 58 ms 2952 KB Output is correct
41 Correct 69 ms 2948 KB Output is correct
42 Correct 77 ms 2952 KB Output is correct
43 Correct 34 ms 2056 KB Output is correct
44 Correct 41 ms 2440 KB Output is correct
45 Correct 51 ms 2952 KB Output is correct
46 Correct 52 ms 2952 KB Output is correct
47 Correct 52 ms 2952 KB Output is correct
48 Correct 51 ms 2952 KB Output is correct
49 Correct 35 ms 2184 KB Output is correct
50 Correct 52 ms 2952 KB Output is correct
51 Correct 51 ms 2952 KB Output is correct
52 Correct 34 ms 2952 KB Output is correct
53 Correct 36 ms 2952 KB Output is correct
54 Correct 50 ms 2952 KB Output is correct
55 Correct 37 ms 2952 KB Output is correct
56 Correct 31 ms 2952 KB Output is correct