Submission #683237

# Submission time Handle Problem Language Result Execution time Memory
683237 2023-01-18T02:10:37 Z Github Watching (JOI13_watching) C++14
100 / 100
222 ms 15220 KB
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

#define speedup ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

int n, p, q;
vector<int> events;

bool simulate(int w){
    int dp[n+1][p+1];
    for (int i = 0; i <= n; i++){
        for (int j = 0; j <= p; j++){
            dp[i][j] = 1e9;
        }
    }
    dp[0][0] = 0;
    int lastp = 1, lastq = 1;
    for (int i = 1; i <= n; i++){
        while (events[i] - events[lastp] >= w){
            lastp++;
        }
        while (events[i] - events[lastq] >= 2*w){
            lastq++;
        }
        for (int j = 0; j <= p; j++){
            dp[i][j] = min(dp[i][j], dp[lastq-1][j]+1);
            if (j > 0){
                dp[i][j] = min(dp[i][j], dp[lastp-1][j-1]);
            }
        }
    }
    int mn = 1e9;
    for (int i = 0; i <= p; i++){
        mn = min(mn, dp[n][i]);
    }
    return (mn <= q);
}

int main(){
    speedup
    int arr[10][10];
    cin >> n >> p >> q;
    if (p+q >= n){
        cout << 1 << endl;
        return 0;
    }
    events.resize(n+1);
    events[0] = 0;
    for (int i = 1; i <= n; i++){
        cin >> events[i];
    }
    sort(events.begin(), events.end());
    int low = 1, high = 1e9, mid, ans = 1e9;
    while (high >= low){
        mid = (high+low)/2;
        if (simulate(mid)){
            ans = mid;
            high = mid-1;
        }else{
            low = mid+1;
        }
    }
    cout << ans << endl;
    return 0;
}

Compilation message

watching.cpp: In function 'int main()':
watching.cpp:43:9: warning: unused variable 'arr' [-Wunused-variable]
   43 |     int arr[10][10];
      |         ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 1 ms 328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 1 ms 216 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 3 ms 340 KB Output is correct
8 Correct 18 ms 1236 KB Output is correct
9 Correct 89 ms 6228 KB Output is correct
10 Correct 222 ms 15220 KB Output is correct
11 Correct 14 ms 1036 KB Output is correct
12 Correct 108 ms 8000 KB Output is correct
13 Correct 3 ms 344 KB Output is correct
14 Correct 3 ms 468 KB Output is correct
15 Correct 3 ms 460 KB Output is correct