Submission #532530

# Submission time Handle Problem Language Result Execution time Memory
532530 2022-03-03T05:39:11 Z amunduzbaev JJOOII 2 (JOI20_ho_t2) C++17
100 / 100
14 ms 4692 KB
#include "bits/stdc++.h"
using namespace std;

#define ar array

const int N = 2e5 + 5;
int dp[3][N];

signed main(){
	ios::sync_with_stdio(0); cin.tie(0);
	
	int n, k; cin>>n>>k;
	string s; cin>>s;
	vector<int> a(n);
	for(int i=0;i<n;i++){
		if(s[i] == 'J') a[i] = 0;
		if(s[i] == 'O') a[i] = 1;
		if(s[i] == 'I') a[i] = 2;
	}
	
	memset(dp, -1, sizeof dp);
	for(int j=0;j<3;j++){
		vector<int> p;
		for(int i=0;i<n;i++){
			if(a[i] == j) p.push_back(i);
		} p.push_back(n);
		
		for(int l=k-1;l+1<(int)p.size();l++){
			for(int i=p[l];i<p[l+1];i++) dp[j][i] = p[l-k+1];
		}
	}
	
	int res = 1e9;
	for(int i=0;i<n;i++){
		int l = i;
		for(int j=2;~j && l >= 0;j--){
			l = dp[j][l];
			if(j) l--;
		}
		
		if(l >= 0){
			res = min(res, i - l + 1);
		}
	}
	
	if(res == 1e9) cout<<-1<<"\n";
	else cout<<res - 3 * k<<"\n";
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2636 KB Output is correct
2 Correct 1 ms 2636 KB Output is correct
3 Correct 1 ms 2624 KB Output is correct
4 Correct 1 ms 2620 KB Output is correct
5 Correct 2 ms 2624 KB Output is correct
6 Correct 1 ms 2628 KB Output is correct
7 Correct 1 ms 2628 KB Output is correct
8 Correct 1 ms 2636 KB Output is correct
9 Correct 1 ms 2636 KB Output is correct
10 Correct 1 ms 2636 KB Output is correct
11 Correct 1 ms 2636 KB Output is correct
12 Correct 1 ms 2636 KB Output is correct
13 Correct 1 ms 2636 KB Output is correct
14 Correct 1 ms 2636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2636 KB Output is correct
2 Correct 1 ms 2636 KB Output is correct
3 Correct 1 ms 2624 KB Output is correct
4 Correct 1 ms 2620 KB Output is correct
5 Correct 2 ms 2624 KB Output is correct
6 Correct 1 ms 2628 KB Output is correct
7 Correct 1 ms 2628 KB Output is correct
8 Correct 1 ms 2636 KB Output is correct
9 Correct 1 ms 2636 KB Output is correct
10 Correct 1 ms 2636 KB Output is correct
11 Correct 1 ms 2636 KB Output is correct
12 Correct 1 ms 2636 KB Output is correct
13 Correct 1 ms 2636 KB Output is correct
14 Correct 1 ms 2636 KB Output is correct
15 Correct 1 ms 2632 KB Output is correct
16 Correct 2 ms 2636 KB Output is correct
17 Correct 2 ms 2604 KB Output is correct
18 Correct 2 ms 2636 KB Output is correct
19 Correct 1 ms 2620 KB Output is correct
20 Correct 2 ms 2636 KB Output is correct
21 Correct 2 ms 2636 KB Output is correct
22 Correct 2 ms 2624 KB Output is correct
23 Correct 1 ms 2620 KB Output is correct
24 Correct 2 ms 2624 KB Output is correct
25 Correct 2 ms 2636 KB Output is correct
26 Correct 1 ms 2636 KB Output is correct
27 Correct 1 ms 2636 KB Output is correct
28 Correct 2 ms 2636 KB Output is correct
29 Correct 2 ms 2624 KB Output is correct
30 Correct 1 ms 2636 KB Output is correct
31 Correct 2 ms 2636 KB Output is correct
32 Correct 2 ms 2636 KB Output is correct
33 Correct 1 ms 2636 KB Output is correct
34 Correct 1 ms 2636 KB Output is correct
35 Correct 1 ms 2636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2636 KB Output is correct
2 Correct 1 ms 2636 KB Output is correct
3 Correct 1 ms 2624 KB Output is correct
4 Correct 1 ms 2620 KB Output is correct
5 Correct 2 ms 2624 KB Output is correct
6 Correct 1 ms 2628 KB Output is correct
7 Correct 1 ms 2628 KB Output is correct
8 Correct 1 ms 2636 KB Output is correct
9 Correct 1 ms 2636 KB Output is correct
10 Correct 1 ms 2636 KB Output is correct
11 Correct 1 ms 2636 KB Output is correct
12 Correct 1 ms 2636 KB Output is correct
13 Correct 1 ms 2636 KB Output is correct
14 Correct 1 ms 2636 KB Output is correct
15 Correct 1 ms 2632 KB Output is correct
16 Correct 2 ms 2636 KB Output is correct
17 Correct 2 ms 2604 KB Output is correct
18 Correct 2 ms 2636 KB Output is correct
19 Correct 1 ms 2620 KB Output is correct
20 Correct 2 ms 2636 KB Output is correct
21 Correct 2 ms 2636 KB Output is correct
22 Correct 2 ms 2624 KB Output is correct
23 Correct 1 ms 2620 KB Output is correct
24 Correct 2 ms 2624 KB Output is correct
25 Correct 2 ms 2636 KB Output is correct
26 Correct 1 ms 2636 KB Output is correct
27 Correct 1 ms 2636 KB Output is correct
28 Correct 2 ms 2636 KB Output is correct
29 Correct 2 ms 2624 KB Output is correct
30 Correct 1 ms 2636 KB Output is correct
31 Correct 2 ms 2636 KB Output is correct
32 Correct 2 ms 2636 KB Output is correct
33 Correct 1 ms 2636 KB Output is correct
34 Correct 1 ms 2636 KB Output is correct
35 Correct 1 ms 2636 KB Output is correct
36 Correct 10 ms 4196 KB Output is correct
37 Correct 14 ms 4692 KB Output is correct
38 Correct 11 ms 4552 KB Output is correct
39 Correct 10 ms 4560 KB Output is correct
40 Correct 11 ms 4576 KB Output is correct
41 Correct 11 ms 4552 KB Output is correct
42 Correct 12 ms 4604 KB Output is correct
43 Correct 7 ms 3840 KB Output is correct
44 Correct 8 ms 4028 KB Output is correct
45 Correct 10 ms 4548 KB Output is correct
46 Correct 10 ms 4520 KB Output is correct
47 Correct 10 ms 4548 KB Output is correct
48 Correct 10 ms 4552 KB Output is correct
49 Correct 9 ms 3876 KB Output is correct
50 Correct 10 ms 4548 KB Output is correct
51 Correct 10 ms 4548 KB Output is correct
52 Correct 8 ms 4312 KB Output is correct
53 Correct 9 ms 4564 KB Output is correct
54 Correct 6 ms 4540 KB Output is correct
55 Correct 5 ms 4540 KB Output is correct
56 Correct 5 ms 4552 KB Output is correct