Submission #74572

# Submission time Handle Problem Language Result Execution time Memory
74572 2018-09-04T04:10:32 Z wzy Watching (JOI13_watching) C++11
0 / 100
477 ms 32172 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];

deque<int> small, large;

bool can(int mid){
	for(int i = 0 ; i <= n ; i++){
		for(int j = 0 ; j <= n; j ++) dp[i][j] = 2000000000;
	}
	for(int i = 0 ; i < n; i ++){
		if(v[i] - v[0] + 1 <= mid) dp[i][1] = 0;
		if(v[i] - v[0] + 1 <= 2*mid) dp[i][0] = 1;
	}
	while(small.size()) small.pop_back();
	while(large.size()) large.pop_back();
	small.push_front(0) , large.push_front(0);
	for(int i = 1 ; i < n ; i++){
		while(large.size() && v[i] - v[large.front()]  + 1 > 2*mid){
			large.pop_front();
		}
		while(small.size() && v[i] - v[small.front()] + 1 > mid){
			small.pop_front();
		}
		for(int j = 0 ; j <= min(p , i+1) ; j++){
			if(j) dp[i][j] = min(dp[i][j] , dp[i][j-1]);
			if(j && small.size() && small.front() > 0) dp[i][j] = min(dp[i][j] , dp[small.front() - 1][j-1]);
			if(large.size() && large.front() > 0) dp[i][j] = min(dp[i][j] , dp[large.front() - 1][j] + 1);
			dp[i][j] = min(dp[i][j] , 1 + dp[i-1][j]);
		}
		large.push_back(i);
		small.push_back(i);
	}
	for(int i = 0 ; i <= p ; 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 = 1 , 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:49: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:51: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 3 ms 888 KB Output is correct
2 Correct 2 ms 888 KB Output is correct
3 Correct 2 ms 888 KB Output is correct
4 Correct 3 ms 984 KB Output is correct
5 Correct 3 ms 984 KB Output is correct
6 Correct 3 ms 984 KB Output is correct
7 Correct 2 ms 984 KB Output is correct
8 Correct 2 ms 984 KB Output is correct
9 Incorrect 3 ms 1068 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 154 ms 32064 KB Output is correct
2 Correct 2 ms 32064 KB Output is correct
3 Incorrect 477 ms 32172 KB Output isn't correct
4 Halted 0 ms 0 KB -