Submission #51545

# Submission time Handle Problem Language Result Execution time Memory
51545 2018-06-18T12:23:53 Z tranxuanbach Watching (JOI13_watching) C++17
100 / 100
337 ms 32252 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long

const int N = 2005;
int n, p, q, ans;
int a[N], cnt[N], max2w[N], maxw[N];
int f[N][N];
 
bool check(int mid){
	int cur1 = 1, cur2 = 1;
	for (int i = 1; i <= n; i++){
		for (; cur1 <= n && a[cur1] - a[i] + 1 <= mid; cur1++);
		maxw[i] = cur1 - 1;
		for (; cur2 <= n && a[cur2] - a[i] + 1 <= 2 * mid; cur2++);
		max2w[i] = cur2 - 1;
	}
	memset(f, -1, sizeof(f));
	f[1][0] = maxw[1];
	f[0][1] = max2w[1];
	if (maxw[1] == n || max2w[1] == n){
	    return true;
	}
	for (int i = 0; i <= p; i++){
		for (int j = 0; j <= q; j++){
			if (f[i][j] != -1){
				if (f[i][j] == n){
				    return true;
				}
				f[i][j + 1] = max(f[i][j + 1], max2w[f[i][j] + 1]);
				f[i + 1][j] = max(f[i + 1][j], maxw[f[i][j] + 1]);
			}
		}
	}
	return false;
}

signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> p >> q;
	a[n + 1] = 1e9;
	for (int i = 1; i <= n; i++){
		cin >> a[i];
	}
	sort(a + 1, a + n + 1);	
	if (p + q >= n){
		cout << 1;
		return 0;
	}	
	int l = 1, r = a[n] - a[1] + 1;
	while (l <= r){
		int mid = (l + r) / 2;
		bool kt = check(mid);
		if (kt){
			ans = mid;
			r = mid - 1;
		}
		else{
		    l = mid + 1;
		}
	}
	cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 226 ms 31992 KB Output is correct
2 Correct 2 ms 31992 KB Output is correct
3 Correct 210 ms 32156 KB Output is correct
4 Correct 2 ms 32156 KB Output is correct
5 Correct 2 ms 32156 KB Output is correct
6 Correct 2 ms 32156 KB Output is correct
7 Correct 226 ms 32156 KB Output is correct
8 Correct 236 ms 32156 KB Output is correct
9 Correct 238 ms 32156 KB Output is correct
10 Correct 237 ms 32156 KB Output is correct
11 Correct 235 ms 32192 KB Output is correct
12 Correct 227 ms 32192 KB Output is correct
13 Correct 125 ms 32192 KB Output is correct
14 Correct 143 ms 32192 KB Output is correct
15 Correct 189 ms 32192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 240 ms 32192 KB Output is correct
2 Correct 2 ms 32192 KB Output is correct
3 Correct 3 ms 32192 KB Output is correct
4 Correct 4 ms 32192 KB Output is correct
5 Correct 3 ms 32192 KB Output is correct
6 Correct 3 ms 32192 KB Output is correct
7 Correct 252 ms 32192 KB Output is correct
8 Correct 254 ms 32192 KB Output is correct
9 Correct 252 ms 32192 KB Output is correct
10 Correct 274 ms 32252 KB Output is correct
11 Correct 256 ms 32252 KB Output is correct
12 Correct 337 ms 32252 KB Output is correct
13 Correct 220 ms 32252 KB Output is correct
14 Correct 225 ms 32252 KB Output is correct
15 Correct 238 ms 32252 KB Output is correct