Submission #707954

# Submission time Handle Problem Language Result Execution time Memory
707954 2023-03-10T15:05:46 Z Dan4Life Watching (JOI13_watching) C++17
100 / 100
63 ms 8524 KB
#include <bits/stdc++.h>
using namespace std;
const int mxN = (int)2e3+10, LINF = (int)1e9;
int n, p, q, a[mxN], P[mxN], Q[mxN], dp[mxN][mxN];

bool work(int w){
	for(int i=1,j=1,k=1; i <= n; i++){
		while(j<=n and a[j]-a[i]<w)j++;
		while(k<=n and a[k]-a[i]<2*w)k++;
		P[i]=--j, Q[i]=--k;
	}
	for(int i = 0; i <= p; i++){
		for(int j = 0; j <= q; j++){
			dp[i][j]=0;
			if(i) dp[i][j] = max(dp[i][j], P[dp[i-1][j]+1]);
			if(j) dp[i][j] = max(dp[i][j], Q[dp[i][j-1]+1]);
			if(dp[i][j]>=n) return 1;
		}
	}
	return 0;
}
 
main() {
	cin >> n >> p >> q;
	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 = (int)1e9;
	while(l<r){
		int mid = (l+r)/2;
		if(work(mid)) r=mid;
		else l=mid+1;
	}
	cout << l;
}

Compilation message

watching.cpp:23:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   23 | 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 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 300 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 468 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 2 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 2 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 10 ms 1108 KB Output is correct
9 Correct 12 ms 3668 KB Output is correct
10 Correct 18 ms 8524 KB Output is correct
11 Correct 7 ms 972 KB Output is correct
12 Correct 63 ms 7912 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 340 KB Output is correct