Submission #260206

# Submission time Handle Problem Language Result Execution time Memory
260206 2020-08-09T18:00:34 Z cheissmart JJOOII 2 (JOI20_ho_t2) C++14
100 / 100
12 ms 2052 KB
#include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " " << (x) << endl;
#define V vector

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int k, n;
	string s;
	cin >> n >> k >> s;
	int mx = -1;
	vi js, os, is;
	for(int i = 0; i < n; i++) {
		if(s[i] == 'J') js.PB(i);
		else if(s[i] == 'O') os.PB(i);
		else is.PB(i);
	}
	for(int i = 0; i + k - 1 < (int)js.size(); i++) {
		int j = js[i + k - 1];
		j = lower_bound(ALL(os), j) - os.begin();
		if(j + k - 1 >= (int)os.size()) break;
		j = os[j + k - 1];
		j = lower_bound(ALL(is), j) - is.begin();
		if(j + k - 1 >= (int)is.size()) break;
		j = is[j + k - 1];
		mx = max(mx, js[i] + n - 1 - j);
	}
	if(mx == -1) cout << -1 << endl;
	else {
		cout << n-mx-3*k << endl;
	}
	
	
}




# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 640 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 640 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 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 0 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 0 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 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 640 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 0 ms 384 KB Output is correct
14 Correct 0 ms 384 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 0 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 0 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 0 ms 384 KB Output is correct
36 Correct 10 ms 1572 KB Output is correct
37 Correct 12 ms 1864 KB Output is correct
38 Correct 11 ms 2036 KB Output is correct
39 Correct 11 ms 2052 KB Output is correct
40 Correct 6 ms 2020 KB Output is correct
41 Correct 8 ms 2036 KB Output is correct
42 Correct 12 ms 1924 KB Output is correct
43 Correct 3 ms 1376 KB Output is correct
44 Correct 3 ms 1524 KB Output is correct
45 Correct 5 ms 2052 KB Output is correct
46 Correct 4 ms 1920 KB Output is correct
47 Correct 4 ms 2052 KB Output is correct
48 Correct 4 ms 2052 KB Output is correct
49 Correct 3 ms 1292 KB Output is correct
50 Correct 4 ms 1924 KB Output is correct
51 Correct 4 ms 1924 KB Output is correct
52 Correct 4 ms 1608 KB Output is correct
53 Correct 4 ms 1864 KB Output is correct
54 Correct 5 ms 2052 KB Output is correct
55 Correct 4 ms 2052 KB Output is correct
56 Correct 3 ms 2052 KB Output is correct