Submission #136443

# Submission time Handle Problem Language Result Execution time Memory
136443 2019-07-25T10:17:49 Z egorlifar Watching (JOI13_watching) C++17
0 / 100
18 ms 4472 KB
/*
ЗАПУСКАЕМ
░ГУСЯ░▄▀▀▀▄░РАБОТЯГУ░░
▄███▀░◐░░░▌░░░░░░░
░░░░▌░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░▄▀▒▒▀▀▀▀▄
░░░▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄
░░░▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░░░▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▄▄▀▄
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░▄▄▌▌▄▌▌░░░░░
 */
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
 
using namespace std;
template<typename T1, typename T2>inline void chkmin(T1 &x, T2 y) { if (x > y) x = y; }
template<typename T1, typename T2>inline void chkmax(T1 &x, T2 y) { if (x < y) x = y; }
#define sz(c) (int)(c).size()
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define left left224
#define right right224
#define next next224
#define rank rank224
#define prev prev224
#define y1 y1224
#define read(FILENAME) freopen((FILENAME + ".in").c_str(), "r", stdin)
#define write(FILENAME) freopen((FILENAME + ".out").c_str(), "w", stdout)
#define files(FILENAME) read(FILENAME), write(FILENAME)
#define pb push_back
#define mp make_pair
const string FILENAME = "input";
const int MAXN = 2005;

int n, p, q;
int a[MAXN];
int pos[MAXN], pos1[MAXN];
bool dp[MAXN][MAXN];


bool can(int x) {
    int uk = 0;
    for (int i = 0; i < n; i++) {
        while (uk + 1 < n && a[i] + x - 1 >= a[uk + 1]) {
            uk++;
        }
        pos[i] = uk;
    }
    uk = 0;
    for (int i = 0; i < n; i++) {
        while (uk + 1 < n && a[i] + 2 * x - 1 >= a[uk + 1]) {
            uk++;
        }
        pos1[i] = uk;
    }
    if (p + q >= n) {
        return true;
    }
    memset(dp, 0, sizeof(dp));
    dp[0][0] = true;
    for (int i = 0; i < n; i++) {
        for (int cnt = 0; cnt <= p; cnt++) {
            if (cnt + 1 <= p) {
                dp[pos[i] + 1][cnt + 1] |= dp[i][cnt];
            }
            if (i - cnt < q) {
                dp[pos1[i] + 1][cnt] |= dp[i][cnt];
            }
        }
    }
    for (int cnt = 0; cnt <= p; cnt++) {
        if (dp[n][cnt]) {
            return true;
        }
    }
    return false;
}


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //read(FILENAME); 
    cin >> n >> p >> q;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a, a + n);
    int l = 1;
    int r = 1000000000;
    while (l < r) {
        int mid = (l + r) >> 1;
        if (can(mid)) {
            r = mid; 
        } else {
            l = mid + 1;
        }
    }
    cout << l << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 12 ms 4472 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Incorrect 11 ms 4344 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 4344 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 4 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 4 ms 376 KB Output is correct
6 Correct 4 ms 376 KB Output is correct
7 Incorrect 18 ms 4344 KB Output isn't correct
8 Halted 0 ms 0 KB -