Submission #753874

# Submission time Handle Problem Language Result Execution time Memory
753874 2023-06-06T08:47:26 Z vjudge1 JJOOII 2 (JOI20_ho_t2) C++17
100 / 100
27 ms 3308 KB
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define f first
#define s second

using namespace std;

const ll N = 2e6 + 7;
const ll inf = 1e9;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;

void be(){
    ios_base::sync_with_stdio (0);
    cin.tie (0);
//	freopen("herding.in","r",stdin);
//	freopen("herding.out","w",stdout);
}

void solve (){
	int n, k;
	cin >> n >> k;
	string s;
	cin >> s;
	vector <int> a(n), b(n), c(n);
	for (int i = 0; i < n; ++i){
		if (i) a[i] = a[i - 1], b[i] = b[i - 1], c[i] = c[i - 1];
		if (s[i] == 'J') ++a[i];
		if (s[i] == 'O') ++b[i];
		if (s[i] == 'I') ++c[i];
	}
	int mn = inf;
//	for (int i = 0; i < n; ++i) cout << a[i] << ' ';
//	cout << '\n';
//	for (int i = 0; i < n; ++i) cout << b[i] << ' ';
//	cout << '\n';
//	for (int i = 0; i < n; ++i) cout << c[i] << ' ';
//	cout << '\n';
	bool ok = 0;
	int pos1, pos2, pos3;
	pos1 = lower_bound (a.begin (), a.end (), k) - a.begin ();
	if (pos1 == n) ok = 1;
	if (!ok) pos2 = lower_bound (b.begin () + pos1, b.end (), k + b[pos1]) - b.begin ();
	if (pos2 == n) ok = 1;
	if (!ok) pos3 = lower_bound (c.begin () + pos2, c.end (), k + c[pos2]) - c.begin ();
	if (pos3 == n) ok = 1;
//	cout << pos1 << ' ' << pos2 << ' ' << pos3 << '\n';
	if (!ok) mn = min (mn, (pos3 + 1 - 3 * k));
	for (int i = 1; i < n; ++i){
		pos1 = lower_bound (a.begin () + i, a.end (), k + a[i - 1]) - a.begin ();
		if (pos1 == n) break;
		pos2 = lower_bound (b.begin () + pos1, b.end (), k + b[pos1]) - b.begin ();
		if (pos2 == n) break;
		pos3 = lower_bound (c.begin () + pos2, c.end (), k + c[pos2]) - c.begin ();
		if (pos3 == n) break;
 		mn = min (mn, (pos3 - i - 3 * k + 1));
//		cout << i << ' ' << pos1 << ' ' << pos2 << ' ' << pos3 << '\n';
	}
	if (mn == inf) mn = -1;
	cout << mn;
}

main (){
	be ();
	ll tt = 1;
//	cin >> tt;
	for (ll i = 1; i <= tt; ++i){
//		cout << "Case " << i << ':';
		solve ();
	}
	return 0;
}

Compilation message

ho_t2.cpp:64:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   64 | main (){
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 316 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 316 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 324 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 0 ms 320 KB Output is correct
27 Correct 1 ms 316 KB Output is correct
28 Correct 1 ms 320 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 320 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 316 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 324 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 0 ms 320 KB Output is correct
27 Correct 1 ms 316 KB Output is correct
28 Correct 1 ms 320 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 320 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 320 KB Output is correct
36 Correct 19 ms 2888 KB Output is correct
37 Correct 21 ms 3168 KB Output is correct
38 Correct 27 ms 3264 KB Output is correct
39 Correct 21 ms 3168 KB Output is correct
40 Correct 9 ms 3204 KB Output is correct
41 Correct 16 ms 3308 KB Output is correct
42 Correct 23 ms 3168 KB Output is correct
43 Correct 3 ms 2104 KB Output is correct
44 Correct 3 ms 2528 KB Output is correct
45 Correct 5 ms 3168 KB Output is correct
46 Correct 4 ms 3168 KB Output is correct
47 Correct 4 ms 3168 KB Output is correct
48 Correct 4 ms 3144 KB Output is correct
49 Correct 4 ms 2272 KB Output is correct
50 Correct 4 ms 3164 KB Output is correct
51 Correct 4 ms 3168 KB Output is correct
52 Correct 4 ms 3044 KB Output is correct
53 Correct 4 ms 3168 KB Output is correct
54 Correct 9 ms 3168 KB Output is correct
55 Correct 6 ms 3168 KB Output is correct
56 Correct 3 ms 3168 KB Output is correct