Submission #651627

# Submission time Handle Problem Language Result Execution time Memory
651627 2022-10-19T13:18:09 Z Koful123 Watching (JOI13_watching) C++17
50 / 100
1000 ms 74956 KB
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define pb push_back
#define ff first
#define ss second
#define mod 1000000007
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

int n;
vector<int> v,a,b;
vector<vector<vector<bool>>> dp,ok;

bool f(int pos,int p,int q,int w){
	if(p < 0 || q < 0) return false;
	if(pos >= n) return true;
	if(ok[pos][p][q]) return dp[pos][p][q];
	dp[pos][p][q] = (f(a[pos],p-1,q,w) || f(b[pos],p,q-1,w)); ok[pos][p][q] = true;
	return dp[pos][p][q];
}

void solve(){

	int p,q;
	cin >> n >> p >> q;

	v.assign(n,0),a.assign(n,0),b.assign(n,0);
	for(int i=0;i<n;i++){
		cin >> v[i];
	}

	if(p + q >= n){
		cout << 1 << endl;
		return;
	}

	auto check = [&](int m){
		dp.assign(n,vector<vector<bool>>(p+1,vector<bool>(q+1,false)));
		ok.assign(n,vector<vector<bool>>(p+1,vector<bool>(q+1,false)));
		for(int i=0;i<n;i++){
			a[i] = lower_bound(all(v),v[i] + m) - v.begin();
			b[i] = lower_bound(all(v),v[i] + 2*m) - v.begin();
		}

		return f(0,p,q,m);
	};

	sort(all(v));
	int l = 1,r = 1e9;
	while(l < r){
		int m = (l + r) / 2;
		if(check(m)) r = m;
		else l = m + 1;
	}

	cout << l << endl;
}	

signed main(){

	ios::sync_with_stdio(0);
	cin.tie(0);

	int t = 1;
//	cin >> t;

	while(t--)
		solve();

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 3 ms 340 KB Output is correct
9 Correct 2 ms 456 KB Output is correct
10 Correct 19 ms 552 KB Output is correct
11 Correct 17 ms 1108 KB Output is correct
12 Correct 49 ms 1156 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 1064 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 76 ms 4564 KB Output is correct
8 Execution timed out 1096 ms 74956 KB Time limit exceeded
9 Halted 0 ms 0 KB -