Submission #370877

# Submission time Handle Problem Language Result Execution time Memory
370877 2021-02-24T23:02:42 Z saarang123 Watching (JOI13_watching) C++17
100 / 100
541 ms 15424 KB
#include <bits/stdc++.h>
using namespace std;
signed main() {
    std::ios::sync_with_stdio(0);
    std::cout.tie(0);
    std::cin.tie(0);
    #ifdef saarang
    freopen("/home/saarang/Documents/cp/input.txt", "r", stdin);
    freopen("/home/saarang/Documents/cp/output.txt", "w", stdout);
    #endif
    int n, p, q;
    cin >> n >> p >> q;
    vector<int> a(n);
    for(int &x : a)
    	cin >> x;
    if(p + q >= n)
    	return cout << 1 << '\n', 0;
    sort(a.begin(), a.end());
    auto check = [&] (int k) {
    	vector<vector<int>> dp(n, vector<int> (p + 1));
    	int p1 = 0, p2 = 0;
    	for(int i = 0; i < n; i++) {
    		while(a[i] - a[p1] >= k)
    			p1++;
    		while(a[i] - a[p2] >= 2 * k)
    			p2++;
    		for(int j = 0; j <= p; j++) {
    			if(j) {
    				if(p1 == 0) 
    					dp[i][j] = 0;
    				else if(p2 == 0)
    					dp[i][j] = min(1, dp[p1 - 1][j - 1]);
    				else
    					dp[i][j] = min(dp[p1 - 1][j - 1], dp[p2 - 1][j] + 1);
    			} else {
    				if(p2 == 0)
    					dp[i][j] = 1;
    				else
    					dp[i][j] = dp[p2 - 1][j] + 1;
    			}
    		}
    	}
    	return *min_element(dp[n - 1].begin(), dp[n - 1].end()) <= q;
    };
    int mn = 1, mx = 1000 * 1000 * 1000 + 3;
    while(mn < mx) {
    	int mid = (mn + mx) >> 1;
    	if(check(mid))
    		mx = mid;
    	else
    		mn = mid + 1;
    }
    cout << mn << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 492 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 7 ms 492 KB Output is correct
8 Correct 35 ms 1468 KB Output is correct
9 Correct 210 ms 6424 KB Output is correct
10 Correct 541 ms 15424 KB Output is correct
11 Correct 26 ms 1184 KB Output is correct
12 Correct 297 ms 8248 KB Output is correct
13 Correct 7 ms 492 KB Output is correct
14 Correct 7 ms 620 KB Output is correct
15 Correct 7 ms 620 KB Output is correct