Submission #312586

# Submission time Handle Problem Language Result Execution time Memory
312586 2020-10-13T20:04:56 Z sofapuden JJOOII 2 (JOI20_ho_t2) C++14
100 / 100
21 ms 3952 KB
#include <bits/stdc++.h>

using namespace std;

int main(){
	int n, k; string s; cin >> n >> k >> s;
	vector<int> J, O, I;
	for(int i = 0; i < n; ++i){
		if(s[i] == 'J')J.push_back(i);
		if(s[i] == 'O')O.push_back(i);
		if(s[i] == 'I')I.push_back(i);
	}
	if((int)J.size() < k){cout << -1 << "\n"; return 0;}
	if((int)O.size() < k){cout << -1 << "\n"; return 0;}
	if((int)I.size() < k){cout << -1 << "\n"; return 0;}
	vector<pair<int,int>> J2, O2, I2;
	for(int i = 0; i <= (int)J.size()-k; ++i)J2.push_back({J[i],J[i+k-1]});
	for(int i = 0; i <= (int)O.size()-k; ++i)O2.push_back({O[i],O[i+k-1]});
	for(int i = 0; i <= (int)I.size()-k; ++i)I2.push_back({I[i],I[i+k-1]});
	int p1 = 0, p2 = -1, p3 = 0;
	int ans = 2000000;
	while(p2 < (int)O2.size()-1){
		p2++;
		if(J2[p1].second > O2[p2].first)continue;
		while(J2[p1].second < O2[p2].first && p1 < (int)J2.size()-1){
			p1++;
		}
		if(J2[p1].second > O2[p2].first)p1--;
		while(O2[p2].second > I2[p3].first && p3 < (int)I2.size()-1){
			p3++;
		}
		if(O2[p2].second > I2[p3].first)break;
		ans = min(ans, I2[p3].second-J2[p1].first);
	}
	cout << (ans == 2000000 ? -1 : ans-3*k+1) << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 0 ms 256 KB Output is correct
13 Correct 0 ms 256 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 0 ms 256 KB Output is correct
13 Correct 0 ms 256 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 0 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 0 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 1 ms 256 KB Output is correct
12 Correct 0 ms 256 KB Output is correct
13 Correct 0 ms 256 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 0 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 0 ms 384 KB Output is correct
32 Correct 1 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 1 ms 384 KB Output is correct
35 Correct 1 ms 384 KB Output is correct
36 Correct 17 ms 2948 KB Output is correct
37 Correct 19 ms 3900 KB Output is correct
38 Correct 19 ms 3944 KB Output is correct
39 Correct 19 ms 3072 KB Output is correct
40 Correct 17 ms 2780 KB Output is correct
41 Correct 18 ms 2924 KB Output is correct
42 Correct 21 ms 3952 KB Output is correct
43 Correct 9 ms 1800 KB Output is correct
44 Correct 12 ms 2420 KB Output is correct
45 Correct 16 ms 2816 KB Output is correct
46 Correct 16 ms 2808 KB Output is correct
47 Correct 18 ms 2812 KB Output is correct
48 Correct 19 ms 2832 KB Output is correct
49 Correct 11 ms 1800 KB Output is correct
50 Correct 17 ms 2940 KB Output is correct
51 Correct 16 ms 2812 KB Output is correct
52 Correct 13 ms 1612 KB Output is correct
53 Correct 14 ms 1740 KB Output is correct
54 Correct 16 ms 3844 KB Output is correct
55 Correct 13 ms 2056 KB Output is correct
56 Correct 11 ms 1800 KB Output is correct