답안 #147036

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
147036 2019-08-27T08:32:44 Z ijk1111 구경하기 (JOI13_watching) C++14
0 / 100
3 ms 504 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

#define N 2001
int n, p, q, dp[N][N];
ll a[N];

int binsearch(int l, int r, ll x) {
        int i = (l+r)/2;

        while (l != i && i != r) {
                if (a[i] <= x)
                        l = i;
                else
                        r = i;

                i = (l+r)/2;
        }

        for (int i = l; i <= r; i++)
                if (a[i] > x)
                        return i;
        return n+1;
}

bool check(int w) {
        for (int i = 0; i <= p; i++)
                for (int j = 0; j <= q; j++)
                        dp[i][j] = 0;

        dp[0][1] = binsearch(1, n, a[1]+1ll*2*w-1)-1;
        dp[1][0] = binsearch(1, n, a[1]+1ll*w-1)-1;
        for (int i = 1; i <= p; i++)
                for (int j = 1; j <= q; j++) {
                        int tmp1 = binsearch(1, n, a[dp[i-1][j]+1]+1ll*w-1) - 1;
                        int tmp2 = binsearch(1, n, a[dp[i][j-1]+1]+1ll*2*w-1) - 1;

                        dp[i-1][j] = max(dp[i-1][j], tmp1);
                        dp[i][j-1] = max(dp[i][j-1], tmp2);

                        if (dp[i][j-1] == n || dp[i-1][j] == n)
                                return true;
                }

        return false;
}

signed main() {
        ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

        cin >> n >> p >> q;
        for (int i = 1; i <= n; i++)
                cin >> a[i];

        if (p+q >= n) {
                cout << 1 << '\n';

                return 0;
        }

        sort(a+1, a+1+n);

        int l = 1, r = 1000000000, ans = 0;

        while (l <= r) {
                int mid = (l+r)/2;

                if (check(mid)) {
                        ans = mid;
                        r = mid-1;
                }
                else l = mid+1;
        }

        cout << ans << '\n';

        return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Incorrect 2 ms 376 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 460 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Incorrect 3 ms 504 KB Output isn't correct
8 Halted 0 ms 0 KB -