Submission #727743

# Submission time Handle Problem Language Result Execution time Memory
727743 2023-04-21T08:51:10 Z sandry24 Watching (JOI13_watching) C++17
100 / 100
291 ms 7976 KB
#include <bits/stdc++.h>
using namespace std;

//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define pb push_back
#define mp make_pair
#define f first
#define s second

const int maxn = 2005;
vector<ll> events;
int n, small, large;

bool possible(ll w){
    vector<ll> small_range(maxn), large_range(maxn);
    int j = 0;
    for(int i = 0; i < n; i++){
        while(j < n && events[j] - events[i] < w)
            j++;
        small_range[i+1] = j;
        j--;
    }
    j = 0;
    for(int i = 0; i < n; i++){
        while(j < n && events[j] - events[i] < 2*w)
            j++;
        large_range[i+1] = j;
        j--;
    }
    small_range[n+1] = large_range[n+1] = n;
    vector<vector<ll>> dp(small+1, vector<ll>(large+1));
    //dp[i][j] = highest index you can cover with i small j big
    for(int i = 0; i <= small; i++){
        for(int j = 0; j <= large; j++){
            if(i > 0)
                dp[i][j] = max(dp[i][j], small_range[dp[i-1][j] + 1]);
            if(j > 0)
                dp[i][j] = max(dp[i][j], large_range[dp[i][j-1] + 1]);
        }
    }
    return (dp[small][large] >= n);
}

void solve(){
    cin >> n >> small >> large;
    if(small + large >= n){
        cout << 1 << '\n';
        return;
    }
    events = vector<ll>(n);
    for(int i = 0; i < n; i++){
        cin >> events[i];
    }
    sort(events.begin(), events.end());
    ll current = 0;
    for(ll add = 1e9; add > 0; add /= 2){
        //cerr << current << '\n';
        while(!possible(current+add))
            current += add;
    }
    cout << current+1 << '\n';
}

int main(){
    //freopen("input.txt", "r", stdin);
    //freopen("test.out", "w", stdout);
    //ios::sync_with_stdio(0); cin.tie(0);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
}
# 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 0 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 256 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 296 KB Output is correct
15 Correct 1 ms 292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 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 0 ms 212 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 30 ms 1104 KB Output is correct
9 Correct 34 ms 1128 KB Output is correct
10 Correct 49 ms 1748 KB Output is correct
11 Correct 48 ms 1776 KB Output is correct
12 Correct 291 ms 7976 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 2 ms 340 KB Output is correct