답안 #1015352

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1015352 2024-07-06T09:01:09 Z overwatch9 구경하기 (JOI13_watching) C++17
0 / 100
2 ms 856 KB
#include <bits/stdc++.h>
using namespace std;
int n;
vector <int> events;
vector <vector <int>> dp;
vector <vector <int>> ready;
int P, Q;
int solve(int i, int p, int w, int q) {
    if (q > Q)
        return 1e9;
    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, q);
    }
    it = upper_bound(events.begin(), events.end(), events[i] + 2*w - 1) - events.begin();
    ans = min(ans, solve(it, p, w, q+1) + 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);
    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, 0) <= Q)
            hi = mid;
        else
            lo = mid + 1;
    }
    cout << lo << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 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 Incorrect 0 ms 348 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 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 Incorrect 2 ms 856 KB Output isn't correct
8 Halted 0 ms 0 KB -