Submission #1106455

# Submission time Handle Problem Language Result Execution time Memory
1106455 2024-10-30T11:17:50 Z xnqs Watching (JOI13_watching) C++17
50 / 100
390 ms 262144 KB
// dp solution just so i can see if its correct
 
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <utility>
#include <algorithm>
#include <cstring>
 
int x, p, q;
std::vector<int> arr;
std::vector<std::vector<std::vector<char>>> dp;
 
char sol(int pos, int a, int b, int cap) {
	if (a>p||b>q) {
		return 0;
	}
	if (pos==x) {
		return 1;
	}
	if (dp[pos][a][b]!=-1) {
		return dp[pos][a][b];
	}
 
	char ret = 0;
	for (int i = pos; i < x; i++) {
		if (arr[i]-arr[pos]+1 <= cap) {
			ret |= sol(i+1,a+1,b,cap);
		}
		if (arr[i]-arr[pos]+1 <= 2*cap) {
			ret |= sol(i+1,a,b+1,cap);
		}
	}
	return dp[pos][a][b] = ret;
}
 
bool can_solve(int cap, bool debug = 0) {
	dp.assign(x,std::vector<std::vector<char>>(p+1,std::vector<char>(q+1,-1)));
	return sol(0,0,0,cap);
}
 
int main() {
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(NULL);
	std::cout.tie(NULL);
 
	std::cin >> x >> p >> q;
 
	// we only need at most x cameras in total, out of which we'll greedily take as many big cameras as possible
	if (p+q>x) {
		q = std::min(q, x);
		p = x-q;
	}
 
	for (int i = 0, tmp; i < x; i++) {
		std::cin >> tmp;
		arr.emplace_back(tmp);
	}
 
	std::sort(arr.begin(),arr.end());
	const auto bs = [&]() {
		int ret = 1000000001;
		int l = 1, r = 1000000000;
		while (l<=r) {
			int m = (l+r)>>1;
			if (can_solve(m)) {
				ret = m;
				r = m-1;
			}
			else {
				l = m+1;
			}
		}
		return ret;
	};
 
	std::cout << bs() << "\n";
	//can_solve(bs(),1);
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 58 ms 848 KB Output is correct
5 Correct 5 ms 336 KB Output is correct
6 Correct 5 ms 336 KB Output is correct
7 Correct 5 ms 336 KB Output is correct
8 Correct 14 ms 336 KB Output is correct
9 Correct 16 ms 336 KB Output is correct
10 Correct 76 ms 616 KB Output is correct
11 Correct 90 ms 592 KB Output is correct
12 Correct 178 ms 848 KB Output is correct
13 Correct 22 ms 336 KB Output is correct
14 Correct 19 ms 512 KB Output is correct
15 Correct 20 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 390 ms 760 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Runtime error 170 ms 262144 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -