Submission #365290

# Submission time Handle Problem Language Result Execution time Memory
365290 2021-02-11T11:38:14 Z Bill_00 Watching (JOI13_watching) C++14
50 / 100
1000 ms 15724 KB
#include <bits/stdc++.h>
using namespace std;
int a[2001];
int dp[2001][100001];
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n,p,q;
	cin >> n >> p >> q;
	for(int i=1;i<=n;i++){
		cin >> a[i];
	}
	sort(a+1,a+n+1);
	if(p>=n || q>=n || p+q>=n){
		cout << 1;
		return 0;
	}
	int l=1,r=1000000000;
	while(l!=r){
		for(int i=1;i<=p;i++){
			dp[0][i]=0;
		}
		for(int i=1;i<=n;i++){
			dp[i][0]=1e9;
		}
		int mid=l+r>>1;
		for(int i=1;i<=n;i++){
			for(int j=1;j<=p;j++){
				int b=a[i]-mid+1;
				int id=lower_bound((a+1),(a+n+1),b)-(a+1);
				b=a[i]-2*mid+1;
				int id1=lower_bound((a+1),(a+n+1),b)-(a+1);
				dp[i][j]=min(dp[id][j-1],dp[id1][j]+1);
			}
		}
		if(dp[n][p]>q){
			l=mid+1;
		}
		else r=mid;
	}
	//cout << l << endl;
	int mid=l;
	for(int i=1;i<=p;i++){
		dp[0][i]=0;
	}
	for(int i=1;i<=n;i++){
		dp[i][0]=1e9;
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=p;j++){
			int b=a[i]-mid+1;
			int id=lower_bound((a+1),(a+n+1),b)-(a+1);
			b=a[i]-2*mid+1;
			int id1=lower_bound((a+1),(a+n+1),b)-(a+1);
			dp[i][j]=min(dp[id][j-1],dp[id1][j]+1);
			//cout << dp[i][j] << ' ' << i << ' ' << j << endl;
		}
	}
	if(dp[n][p]>q){
		l++;
	}
	cout << l;
}

Compilation message

watching.cpp: In function 'int main()':
watching.cpp:27:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   27 |   int mid=l+r>>1;
      |           ~^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 876 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 876 KB Output is correct
8 Correct 1 ms 876 KB Output is correct
9 Correct 2 ms 876 KB Output is correct
10 Correct 2 ms 876 KB Output is correct
11 Correct 5 ms 876 KB Output is correct
12 Correct 4 ms 876 KB Output is correct
13 Correct 1 ms 876 KB Output is correct
14 Correct 1 ms 876 KB Output is correct
15 Correct 1 ms 876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 9836 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 35 ms 9964 KB Output is correct
8 Correct 226 ms 10860 KB Output is correct
9 Execution timed out 1093 ms 15724 KB Time limit exceeded
10 Halted 0 ms 0 KB -