Submission #507628

# Submission time Handle Problem Language Result Execution time Memory
507628 2022-01-12T21:01:56 Z thiago_bastos Watching (JOI13_watching) C++17
0 / 100
294 ms 16860 KB
#include "bits/stdc++.h"

using namespace std;

using i64 = long long;
using u64 = unsigned long long;
using i32 = int;
using u32 = unsigned;
using i16 = short;
using u16 = unsigned short;
using ld = long double;
using ii = pair<int, int>;

const int inf = 1e9, N = 2e3 + 100;

int n, p, q;
array<int, N> dp[2];

vector<int> a;

bool f(int w) {
	int ans = 0;
	for(int i = 0; i <= n; ++i) dp[0][i] = -inf;
	dp[0][0] = 0;
	for(int i = 1; i <= p + q; ++i) {
		int hi[2] = {0};
		for(int i = 0; i <= n; ++i) dp[1][i] = -inf;
		for(int k = 0; k < n; ++k) {
			while(hi[0] < n && a[hi[0]] - a[k] < w) ++hi[0];
			while(hi[1] < n && a[hi[1]] - a[k] < 2 * w) ++hi[1];
			dp[1][hi[0]] = max(dp[1][hi[0]], dp[0][k] + 1);
			dp[1][hi[1]] = max(dp[1][hi[1]], dp[0][k]);
		}
		swap(dp[0], dp[1]);
		ans = max(ans, dp[0][n]);
	}
	return ans >= p;
}

void solve() {

	cin >> n >> p >> q;

	a.resize(n);

	for(int i = 0; i < n; ++i) cin >> a[i];

	if(p + q >= n) {
		cout << "1\n";
		return;
	}

	sort(a.begin(), a.end());

	vector<int> d;

	for(int i = 0; i < n; ++i) {
		for(int j = i + 1; j < n; ++j) {
			d.push_back(a[j] - a[i] + 1);
			d.push_back((a[j] - a[i] + 2) / 2);
		}
	}

	sort(d.begin(), d.end());
	d.resize(unique(d.begin(), d.end()) - d.begin());

	int lo = 0, hi = (int)d.size() - 1;

	while(lo < hi) {
		int mid = (lo + hi) / 2;
		if(f(d[mid])) hi = mid;
		else lo = mid + 1;	
	}

	cout << d[hi] << '\n';
}		

int main() {
	ios_base :: sync_with_stdio(false);
	cin.tie(0);
	int t = 1;
	//cin >> t;
	while(t--) solve();
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 0 ms 312 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 312 KB Output is correct
8 Correct 1 ms 316 KB Output is correct
9 Incorrect 1 ms 332 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 293 ms 16816 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 1 ms 324 KB Output is correct
7 Incorrect 294 ms 16860 KB Output isn't correct
8 Halted 0 ms 0 KB -