Submission #74571

# Submission time Handle Problem Language Result Execution time Memory
74571 2018-09-04T02:30:24 Z wzy Watching (JOI13_watching) C++11
0 / 100
34 ms 8608 KB
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define F first
#define S second
#define pb push_back
#define int long long
int n , p , q;
vector<int> v;

int dp[2002][2002];

int si[2002] , li[2002];

bool can(int mid){
	if(p+q >= n) return 1;
	for(int i = 0 ; i <= 2001 ; i++){
		si[i] = i , li[i] = i;
		for(int j = 0 ; j <= min(p, i+1) ; j++){
			dp[i][j] = (i+1) - j;
		}
	}
	for(int i = 0 ; i < n ; i++){
		for(int j = 0 ; j < i ; j++){
			if(v[i] - v[j] + 1  <= mid){
				si[i] = j;
				break;
			}
		}
		for(int j = 0 ; j < i ; j++){
			if(v[i] - v[j]  + 1 <= 2*mid){
				li[i] = j;
				break;
			}
		}
	}
	for(int i = 0 ; i < n; i ++){
		for(int j = 0 ; j <= min(p, i+1) ; j++){
			if(j > 0 ){
				dp[i][j] = min(dp[i][j] , dp[max(si[i] - 1 , 0LL)][j-1]);
			}
			dp[i][j] = min(dp[i][j], dp[max(li[i] - 1 , 0LL)][j] + 1);
			if(li[i] == 0) dp[i][j] = min(dp[i][j] , 1LL);
		}
	}
	for(int i = 0 ; i <= min(p, n) ; i++){
		if(dp[n-1][i] <= q) return true;
	}
	return false;
}

int32_t main(){
	scanf("%lld%lld%lld" , &n , &p , &q);
	v.resize(n);
	for(int i = 0 ; i < n; i ++) scanf("%lld" , &v[i]);
	sort(v.begin() , v.end());
	int l = 0 , r = 1000000000;
	int ansj = 1000000000;
	while(l<=r){
		int mid = (l+r)/2;
		if(can(mid)){
			ansj = mid;
			r = mid - 1;
		}
		else{
			l = mid + 1;
		}
	}
	printf("%lld\n" , ansj);
}

Compilation message

watching.cpp: In function 'int32_t main()':
watching.cpp:53:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld%lld%lld" , &n , &p , &q);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
watching.cpp:55:36: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i = 0 ; i < n; i ++) scanf("%lld" , &v[i]);
                               ~~~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 9 ms 8440 KB Output is correct
2 Incorrect 2 ms 8440 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 34 ms 8608 KB Output is correct
2 Incorrect 2 ms 8608 KB Output isn't correct
3 Halted 0 ms 0 KB -