Submission #503185

# Submission time Handle Problem Language Result Execution time Memory
503185 2022-01-07T12:55:01 Z Abrar_Al_Samit Watching (JOI13_watching) C++17
50 / 100
10 ms 8648 KB
#include<bits/stdc++.h>
using namespace std;
const int MX = 101;
int n;
vector<int>a;
int dp[MX][MX][MX];
int jump[MX][2];
bool solve(int i, int p, int q) {
	if(i==n) return 1;
	if(p+q==0) return 0;
	int &ret = dp[i][p][q];
	if(ret!=-1) return ret;
	ret = 0;
	if(p) ret = solve(jump[i][0], p-1, q);
	if(q) ret |= solve(jump[i][1], p, q-1);
	return ret;
}
void PlayGround() {
	int p, q;
	cin >> n >> p >> q;
	if(p+q>=n) {
		cout << "1\n";
		return;
	}
	for(int i=0; i<n; ++i) {
		int x; cin >> x;
		a.push_back(x);
	}
	sort(a.begin(), a.end());
	int l=1, r=1e9;
	while(l<r) {
		int w = (l+r)/2;
		for(int i=0; i<n; ++i) {
			jump[i][0] = lower_bound(a.begin(), a.end(), a[i]+w) - a.begin();
			jump[i][1] = lower_bound(a.begin(), a.end(), a[i]+w+w) - a.begin();
		}
		memset(dp, -1, sizeof dp);
		if(solve(0, p, q)) {
			r = w;
		} else {
			l = w+1;
		}
	}
	cout << l << endl;
}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	PlayGround();
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4288 KB Output is correct
2 Correct 0 ms 328 KB Output is correct
3 Correct 5 ms 4296 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 5 ms 4296 KB Output is correct
8 Correct 5 ms 4300 KB Output is correct
9 Correct 5 ms 4300 KB Output is correct
10 Correct 10 ms 4300 KB Output is correct
11 Correct 6 ms 4300 KB Output is correct
12 Correct 8 ms 4232 KB Output is correct
13 Correct 5 ms 4296 KB Output is correct
14 Correct 5 ms 4300 KB Output is correct
15 Correct 5 ms 4300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 7 ms 8648 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -