답안 #112132

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
112132 2019-05-17T14:48:20 Z dolphingarlic 구경하기 (JOI13_watching) C++14
0 / 100
1000 ms 23932 KB
#include<bits/stdc++.h>
#define FOR(i, x, y) for (int i = x; i < y; i++)
using namespace std;
typedef long long ll;

int n, p, q;
ll a[2001];
ll dp[2001][2001]; // Max position you can get up to with at most i small and j big
                   // You clearly need at most N cameras

ll binsearch(int x) {
    int l = 1, r = n;
    while (l != r) {
        ll mid = (l + r) / 2;
        if (a[mid] > x) r = mid;
        else l = mid + 1;
    }
    return a[l];
}

bool assign(ll w) {
    FOR(i, 0, min(p, n) + 1) {
        FOR(j, 0, min(q, n) + 1) {
            dp[i][j] = 0;
            if (j) {
                // Binary search for element in a greater than dp[i][j - 1]
                ll x = binsearch(dp[i][j - 1]);
                dp[i][j] = max(dp[i][j], x + 2 * w - 1);
            }
            if (i) {
                // Binary search for element in a greater than dp[i - 1][j]
                ll x = binsearch(dp[i - 1][j]);
                dp[i][j] = max(dp[i][j], x + w - 1);
            }
            // cout << i << ' ' << j << ' ' << dp[i][j] << endl;
        }
    }
    return dp[min(n, p)][min(n, q)] >= a[n];
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> n >> p >> q;
    FOR(i, 1, n + 1) cin >> a[i];
    sort(a + 1, a + n + 1);

    ll l = 1, r = a[n] - a[1];
    while (l != r) {
        // cout << l << ' ' << r << endl;
        ll mid = (l + r) / 2;
        if (assign(mid)) r = mid;
        else l = mid + 1;
    }
    cout << l << '\n';
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Execution timed out 1040 ms 384 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Execution timed out 1067 ms 23932 KB Time limit exceeded
4 Halted 0 ms 0 KB -