Submission #727742

# Submission time Handle Problem Language Result Execution time Memory
727742 2023-04-21T08:48:55 Z sandry24 Watching (JOI13_watching) C++17
0 / 100
2 ms 468 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(n+1), large_range(n+1);
    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--;
    }
    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 300 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Runtime error 1 ms 300 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# 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 308 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 308 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Runtime error 2 ms 468 KB Execution killed with signal 11
8 Halted 0 ms 0 KB -