Submission #764687

# Submission time Handle Problem Language Result Execution time Memory
764687 2023-06-23T21:07:23 Z NK_ Watching (JOI13_watching) C++17
100 / 100
538 ms 16184 KB
// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>

using namespace std;

#define nl '\n'

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

const int INF = 1e9+10;

int main() {
	cin.tie(0)->sync_with_stdio(0);
	
	int N, P, Q; cin >> N >> P >> Q;
	P = min(P, N + 1), Q = min(Q, N + 1);

	V<int> A(N); for(auto& x : A) cin >> x;
	sort(begin(A), end(A));

	auto check = [&](int w) {
		V<V<int>> dp(N + 1, V<int>(P + 1, INF));
		dp[0][0] = 0;
		int RW = 0, R2W = 0;
		for(int i = 0; i < N; i++) for(int p = 0; p <= P; p++) {
			// cout << i << " <-> " << p << endl;
			if (p + 1 <= P) {
				int x = A[i] + w - 1;
				while(RW < N && A[RW] <= x) RW++;
				// cout << i << " " << RW << endl;
				dp[RW][p+1] = min(dp[RW][p+1], dp[i][p] + 1);
			}

			{
				int x = A[i] + 2 * w - 1;
				while(R2W < N && A[R2W] <= x) R2W++;
				// cout << i << " " << R2W << endl;
				dp[R2W][p] = min(dp[R2W][p], dp[i][p] + 1);
			}
			// cout << endl;
		}

		bool ans = 0;
		for(int p = 0; p <= P; p++) {
			int q = dp[N][p] - p;
			if (q <= Q) ans = 1;
		}

		return ans;
	};

	int lo = 1, hi = INF;
	while(lo < hi) {
		int mid = (lo + hi) / 2;

		if (check(mid)) hi = mid;
		else lo = mid + 1;
	}

	cout << lo << nl;



    return 0;
}


# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 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
# Verdict Execution time Memory Grader output
1 Correct 3 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 388 ms 12212 KB Output is correct
4 Correct 538 ms 16184 KB Output is correct
5 Correct 21 ms 1076 KB Output is correct
6 Correct 528 ms 16128 KB Output is correct
7 Correct 5 ms 468 KB Output is correct
8 Correct 31 ms 1460 KB Output is correct
9 Correct 179 ms 6332 KB Output is correct
10 Correct 497 ms 15328 KB Output is correct
11 Correct 24 ms 1092 KB Output is correct
12 Correct 241 ms 8124 KB Output is correct
13 Correct 5 ms 468 KB Output is correct
14 Correct 6 ms 468 KB Output is correct
15 Correct 6 ms 468 KB Output is correct