Submission #923283

# Submission time Handle Problem Language Result Execution time Memory
923283 2024-02-07T05:01:03 Z oblantis Watching (JOI13_watching) C++17
100 / 100
37 ms 15316 KB
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define all(v) v.begin(), v.end()
#define pb push_back
#define ss second
#define ff first
#define vt vector
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int, int> pii;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int inf = 1e9;
const int mod = 1e9+7;
const int maxn = 1e6 + 1;

void solve() {
	int n, p, q;
	cin >> n >> p >> q;
	if(p + q >= n){
		cout << 1;
		return;
	}
	int a[n + 1], dp[n + 1][q + 1];
	a[0] = 0;
	for(int i = 1; i <= n; i++){
		cin >> a[i];
	}
	sort(a, a + n + 1);
	int l = 0, r = inf;
	while(l + 1 < r){
		int w = l + (r - l) / 2;
		for(int i = 0; i <= q; i++)dp[0][i] = 0;
		for(int i = 1, xl = 1, lx = 1; i <= n; i++){
			while(a[i] - a[xl] >= w * 2){
				xl++;
			}
			while(a[i] - a[lx] >= w)lx++;
			dp[i][0] = dp[lx - 1][0] + 1;
			for(int j = 1; j <= q; j++){
				dp[i][j] = min(dp[xl - 1][j - 1], dp[lx - 1][j] + 1);
			}
		}
		if(dp[n][q] <= p)r = w;
		else l = w;
	}
	cout << r;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int times = 1;
	//cin >> times;
	for(int i = 1; i <= times; i++) {
		solve();
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 452 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 452 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 2 ms 348 KB Output is correct
8 Correct 14 ms 6384 KB Output is correct
9 Correct 3 ms 1372 KB Output is correct
10 Correct 3 ms 1116 KB Output is correct
11 Correct 37 ms 15316 KB Output is correct
12 Correct 18 ms 8280 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 604 KB Output is correct