Submission #912718

# Submission time Handle Problem Language Result Execution time Memory
912718 2024-01-19T18:40:11 Z Acanikolic Watching (JOI13_watching) C++14
100 / 100
659 ms 30476 KB
#include <bits/stdc++.h>
		 		
#define int long long 
		 
#define pb push_back 
		
#define F first
		 
#define S second
		 
using namespace std;
		 
const int N = 2000 + 10;
		 
const int mod = 1e9 + 7;
		 
const int inf = 1e18;	
 
vector<int>a;
				
bool check(int n,int p,int q,int x) {
	vector<vector<int>>dp(n + 1,vector<int>(p + 2,inf));
	for(int i = 0; i <= p; i++) dp[0][i] = 0;
	int ans1 = 1,ans2 = 1;
	for(int i = 1; i <= n; i++) {
		while(ans1 + 1 <= n && a[i] + x - 1 >= a[ans1 + 1]) ans1 += 1;
		while(ans2 + 1 <= n && a[i] + 2 * x - 1 >= a[ans2 + 1]) ans2 += 1;
		for(int j = 0; j <= p; j++) {
			if(j > 0) dp[i][j] = min(dp[i][j],dp[i - 1][j - 1]);
			//dp[i][j] = min(dp[i][j],dp[i - 1][j] + 1);
			dp[ans1][j + 1] = min(dp[ans1][j + 1],dp[i - 1][j]);
			dp[ans2][j] = min(dp[ans2][j],dp[i - 1][j] + 1);
		}
	}
	if(dp[n][p] <= q) return true;
	return false;
}
																						
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	
	int n,p,q;
	cin >> n >> p >> q;
	a.resize(n + 1);
	for(int i = 1; i <= n; i++) cin >> a[i];
  	if(n <= p + q) {
      cout << 1;
      return 0;
    }
	sort(a.begin() + 1,a.end());
	int l = 1,r = 1e9,ans = -1;
	while(l <= r) {
		int mid = (l + r) / 2;
		if(check(n,p,q,mid)) {
			ans = mid;
			r = mid - 1;
		}else {
			l = mid + 1;
		}
	}
	cout << ans;
	//cout << check(9);
    return 0; 
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 352 KB Output is correct
2 Correct 1 ms 352 KB Output is correct
3 Correct 1 ms 352 KB Output is correct
4 Correct 1 ms 352 KB Output is correct
5 Correct 1 ms 352 KB Output is correct
6 Correct 1 ms 352 KB Output is correct
7 Correct 6 ms 820 KB Output is correct
8 Correct 33 ms 2628 KB Output is correct
9 Correct 225 ms 12496 KB Output is correct
10 Correct 659 ms 30476 KB Output is correct
11 Correct 25 ms 2124 KB Output is correct
12 Correct 322 ms 16024 KB Output is correct
13 Correct 4 ms 616 KB Output is correct
14 Correct 7 ms 1008 KB Output is correct
15 Correct 6 ms 852 KB Output is correct