Submission #766332

# Submission time Handle Problem Language Result Execution time Memory
766332 2023-06-25T13:48:38 Z NK_ JJOOII 2 (JOI20_ho_t2) C++17
100 / 100
220 ms 1572 KB
// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>

using namespace std;

#define nl '\n'
#define sz(x) int(x.size())

template<class T> using V = vector<T>;
using str = string;

int main() {
	cin.tie(0)->sync_with_stdio(0);
	
	int N, K; cin >> N >> K;
	str S; cin >> S;

	V<deque<int>> oc(3);

	auto verify = [&]() {
		// cout << "VERIFY: " << endl;
		int cur = -1;
		for(int t = 0; t < 3; t++) {
			int lo = 0, hi = sz(oc[t]);
			while(lo < hi) {
				int mid = (lo + hi) / 2;

				if (oc[t][mid] >= cur) hi = mid;
				else lo = mid + 1;
			}	

			int I = lo + K - 1; 
			if (I >= sz(oc[t])) return 0;
			cur = oc[t][I];
		}
		return 1;
	};

	auto check = [&](int w) {
		for(int t = 0; t < 3; t++) oc[t].clear();

		for(int i = 0; i < w; i++) {
			int t = (S[i] == 'J' ? 0 : (S[i] == 'O' ? 1 : 2));
			oc[t].push_back(i);
		}

		if (verify()) return 1;

		for(int i = w; i < N; i++) {
			int tb = (S[i-w] == 'J' ? 0 : (S[i-w] == 'O' ? 1 : 2));
			oc[tb].pop_front();

			int tf = (S[i] == 'J' ? 0 : (S[i] == 'O' ? 1 : 2));
			oc[tf].push_back(i);

			if (verify()) return 1;
		}
		return 0;
	};

	int lo = 3 * K, hi = N + 1;
	while(lo < hi) {
		int mid = (lo + hi) / 2;
			
		// cout << lo << " <-> " << mid << " <-> " << hi << endl;

		if (check(mid)) hi = mid;
		else lo = mid + 1;
	}
	if (lo == N + 1) cout << -1 << nl;
	else cout << lo - 3 * K << nl;

    return 0;
}


# 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 320 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 316 KB Output is correct
8 Correct 0 ms 316 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 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 320 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 316 KB Output is correct
8 Correct 0 ms 316 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 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 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 2 ms 340 KB Output is correct
20 Correct 2 ms 336 KB Output is correct
21 Correct 2 ms 320 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 284 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 320 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 2 ms 212 KB Output is correct
34 Correct 1 ms 316 KB Output is correct
35 Correct 1 ms 340 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 320 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 316 KB Output is correct
8 Correct 0 ms 316 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 0 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 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 2 ms 340 KB Output is correct
20 Correct 2 ms 336 KB Output is correct
21 Correct 2 ms 320 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 284 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 320 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 2 ms 212 KB Output is correct
34 Correct 1 ms 316 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 2 ms 992 KB Output is correct
37 Correct 2 ms 1120 KB Output is correct
38 Correct 2 ms 1120 KB Output is correct
39 Correct 220 ms 1148 KB Output is correct
40 Correct 96 ms 1372 KB Output is correct
41 Correct 152 ms 1176 KB Output is correct
42 Correct 174 ms 1120 KB Output is correct
43 Correct 22 ms 1088 KB Output is correct
44 Correct 27 ms 1192 KB Output is correct
45 Correct 35 ms 1528 KB Output is correct
46 Correct 37 ms 1572 KB Output is correct
47 Correct 38 ms 1544 KB Output is correct
48 Correct 36 ms 1528 KB Output is correct
49 Correct 26 ms 1164 KB Output is correct
50 Correct 36 ms 1548 KB Output is correct
51 Correct 35 ms 1520 KB Output is correct
52 Correct 18 ms 1504 KB Output is correct
53 Correct 21 ms 1516 KB Output is correct
54 Correct 66 ms 1144 KB Output is correct
55 Correct 40 ms 1368 KB Output is correct
56 Correct 2 ms 1504 KB Output is correct