Submission #1015026

# Submission time Handle Problem Language Result Execution time Memory
1015026 2024-07-06T02:12:26 Z aufan Watching (JOI13_watching) C++17
0 / 100
205 ms 604 KB
#include <bits/stdc++.h>
#define int long long
#define fi first
#define se second

using namespace std;

const int inf = 1e9;

int32_t main()
{
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        
        int n, p, q;
        cin >> n >> p >> q;

        vector<int> a(n + 1);
        for (int i = 1; i <= n; i++) cin >> a[i];
        sort(a.begin() + 1, a.end());

        int lf = 0, rg = inf, ans = -1;
        while (lf <= rg) {
                int md = (lf + rg) / 2;

                vector<vector<pair<int, int>>> dp(n + 1, vector<pair<int, int>>(2, {inf, inf}));
                dp[0][0] = {0, 0};
                dp[0][1] = {0, 0};
                for (int i = 1; i <= n; i++) {
                        for (int j = 1; j <= i; j++) {
                                if (a[i] - a[j] + 1 <= md) {
                                        dp[i][0] = min(dp[i][0], {dp[j - 1][0].fi + 1, dp[j - 1][0].se});
                                        dp[i][0] = min(dp[i][0], {dp[j - 1][1].se + 1, dp[j - 1][1].fi});
                                }

                                if (a[i] - a[j] + 1 <= 2 * md) {
                                        dp[i][1] = min(dp[i][1], {dp[j - 1][0].se + 1, dp[j - 1][0].fi});
                                        dp[i][1] = min(dp[i][1], {dp[j - 1][1].fi + 1, dp[j - 1][1].se});
                                }
                        }
                }

                int ok = 0;
                if (dp[n][0].fi <= p && dp[n][0].se <= q) ok = 1;
                if (dp[n][1].fi <= q && dp[n][1].se <= p) ok = 1;
                
                if (ok) {
                        ans = md;
                        rg = md - 1;
                } else {
                        lf = md + 1;
                }
        }

        cout << ans << '\n';
        
        return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Incorrect 1 ms 348 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 205 ms 604 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 72 ms 600 KB Output is correct
4 Incorrect 71 ms 604 KB Output isn't correct
5 Halted 0 ms 0 KB -