답안 #587772

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
587772 2022-07-02T10:58:14 Z MohamedFaresNebili 구경하기 (JOI13_watching) C++14
100 / 100
383 ms 31820 KB
#include <bits/stdc++.h>
/// #pragma GCC optimize ("Ofast")
/// #pragma GCC target ("avx2")
/// #pragma GCC optimize("unroll-loops")

        using namespace std;

        using ll = long long;
        using ii = pair<ll, ll>;
        using vi = vector<int>;

        #define ff first
        #define ss second
        #define pb push_back
        #define all(x) (x).begin(), (x).end()
        #define lb lower_bound
        #define int ll

        const int MOD = 1000 * 1000 * 1000 + 7;

        int N, P, Q, A[2001], DP[2001][2001];
        int solve(int v) {
            int X[N], Y[N];
            for(int l = 0, i = 0; l < N; l++) {
                while(A[l] - A[i] >= v) i++;
                X[l] = i;
            }
            for(int l = 0, i = 0; l < N; l++) {
                while(A[l] - A[i] >= 2 * v) i++;
                Y[l] = i;
            }
            for(int l = 0; l <= N; l++)
                for(int i = 0; i <= P; i++)
                    DP[l][i] = 1e9 + 7;
            DP[0][0] = 0;
            for(int l = 1; l <= N; l++) {
                for(int i = 0; i <= P; i++) {
                    if(i > 0) DP[l][i] = min(DP[l][i], DP[X[l - 1]][i - 1]);
                    if(DP[Y[l - 1]][i - 1] != 1e9 + 7)
                        DP[l][i] = min(DP[l][i], DP[Y[l - 1]][i] + 1);
                }
            }
            for(int l = 0; l <= P; l++)
                if(DP[N][l] <= Q) return 1;
            return 0;
        }

		int32_t main() {
            ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
            cin >> N >> P >> Q;
            P = min(P, N), Q = min(Q, N);
            for(int l = 0; l < N; l++) cin >> A[l];
            sort(A, A + N);
            int lo = 1, hi = 1e9, res = 1e9 + 7;
            while(lo <= hi) {
                int md = (lo + hi) / 2;
                if(solve(md)) hi = md - 1, res = md;
                else lo = md + 1;
            }
            cout << res << "\n";
            return 0;
		}

# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 724 KB Output is correct
2 Correct 0 ms 324 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 2 ms 716 KB Output is correct
5 Correct 1 ms 640 KB Output is correct
6 Correct 1 ms 724 KB Output is correct
7 Correct 1 ms 716 KB Output is correct
8 Correct 1 ms 724 KB Output is correct
9 Correct 1 ms 724 KB Output is correct
10 Correct 1 ms 724 KB Output is correct
11 Correct 1 ms 724 KB Output is correct
12 Correct 1 ms 724 KB Output is correct
13 Correct 1 ms 724 KB Output is correct
14 Correct 1 ms 724 KB Output is correct
15 Correct 1 ms 724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 8404 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 299 ms 31700 KB Output is correct
4 Correct 344 ms 31660 KB Output is correct
5 Correct 22 ms 9568 KB Output is correct
6 Correct 354 ms 31820 KB Output is correct
7 Correct 9 ms 8660 KB Output is correct
8 Correct 32 ms 10324 KB Output is correct
9 Correct 168 ms 20180 KB Output is correct
10 Correct 383 ms 31744 KB Output is correct
11 Correct 25 ms 9812 KB Output is correct
12 Correct 211 ms 23748 KB Output is correct
13 Correct 8 ms 8656 KB Output is correct
14 Correct 10 ms 8736 KB Output is correct
15 Correct 9 ms 8660 KB Output is correct