Submission #1015322

# Submission time Handle Problem Language Result Execution time Memory
1015322 2024-07-06T08:42:34 Z overwatch9 Watching (JOI13_watching) C++17
50 / 100
1000 ms 30544 KB
#include <bits/stdc++.h>
using namespace std;
int n;
vector <int> events;
vector <vector <int>> dp;
vector <vector <int>> ready;
int solve(int i, int p, int w) {
    if (i >= n)
        return 0;
    if (ready[i][p] == w)
        return dp[i][p];
    int ans = 1e9;
    int it;
    if (p >= 1) {
        it = upper_bound(events.begin(), events.end(), events[i] + w - 1) - events.begin();
        ans = solve(it, p-1, w);
    }
    it = upper_bound(events.begin(), events.end(), events[i] + 2*w - 1) - events.begin();
    ans = min(ans, solve(it, p, w) + 1);
    ready[i][p] = w;
    dp[i][p] = ans;
    return ans;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int p, q;
    cin >> n >> p >> q;
    events = vector <int> (n);
    for (int i = 0; i < n; i++)
        cin >> events[i];
    sort(events.begin(), events.end());
    if (p + q >= n) {
        cout << 1 << '\n';
        return 0;
    }
    ready = dp = vector <vector <int>> (n+1, vector <int> (p+1));
    int lo = 1, hi = 1e9;
    while (lo < hi) {
        int mid = lo + (hi - lo) / 2;
        if (solve(0, p, mid) <= q)
            hi = mid;
        else
            lo = mid + 1;
    }
    cout << lo << '\n';
}
# 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 404 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 3 ms 512 KB Output is correct
12 Correct 2 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 604 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 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 2 ms 872 KB Output is correct
8 Correct 77 ms 2608 KB Output is correct
9 Correct 294 ms 12380 KB Output is correct
10 Execution timed out 1064 ms 30544 KB Time limit exceeded
11 Halted 0 ms 0 KB -