Submission #1015183

# Submission time Handle Problem Language Result Execution time Memory
1015183 2024-07-06T07:05:22 Z aufan Watching (JOI13_watching) C++17
100 / 100
319 ms 8256 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());

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

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

                int ok = 0;
                vector<vector<int>> dp(p + 1, vector<int>(q + 1));
                for (int i = 0; i <= p; i++) {
                        for (int j = 0; j <= q; j++) {
                                if (i - 1 >= 0) {
                                        int x = a[dp[i - 1][j] + 1] + md - 1;
                                        int y = upper_bound(a.begin(), a.end(), x) - a.begin() - 1;
                                        dp[i][j] = max(dp[i][j], y);
                                }

                                if (j - 1 >= 0) {
                                        int x = a[dp[i][j - 1] + 1] + 2 * md - 1;
                                        int y = upper_bound(a.begin(), a.end(), x) - a.begin() - 1;
                                        dp[i][j] = max(dp[i][j], y);
                                }

                                if (dp[i][j] == n) {
                                        ok = 1;
                                        goto Next;
                                }
                        }
                }
                Next:;
                
                if (ok) {
                        ans = md;
                        rg = md - 1;
                } else {
                        lf = md + 1;
                }
        }

        cout << ans << '\n';
        
        return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
# 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 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 37 ms 1232 KB Output is correct
9 Correct 48 ms 1244 KB Output is correct
10 Correct 62 ms 1852 KB Output is correct
11 Correct 85 ms 2036 KB Output is correct
12 Correct 319 ms 8256 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct