Submission #1101881

# Submission time Handle Problem Language Result Execution time Memory
1101881 2024-10-17T06:21:25 Z tsengang Watching (JOI13_watching) C++14
0 / 100
366 ms 32076 KB
#include <bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;
ll n,q,k;
struct segtree{
    int n;
    vector<ll>d;
    segtree(ll n){
        d.resize(4*n);
        build(1,1,n);
    }
    void build(ll v,ll l,ll r){
        if(l==r){
            d[v]=0;
            return;
        }
        ll m=(l+r)/2;
        build(v*2,l,m);
        build(v*2+1,m+1,r);
        d[v]=d[v*2]+d[v*2+1];
    }
    ll query(ll v,ll l,ll r,ll L,ll R){
        if(L>R||l>R||L>r) return 0;
        if(L<=l&&r<=R){
            return d[v];
        }
        ll m=(l+r)/2;
        return query(v*2,l,m,L,R)+query(v*2+1,m+1,r,L,R);
    }
    void update(ll v,ll l,ll r,ll pos,ll val){
        if(pos<l||r<pos) return;
        if(l==r){
            d[v]=val;
            return;
        }
        ll m=(l+r)/2;
        update(v*2,l,m,pos,val);
        update(v*2+1,m+1,r,pos,val);
        d[v]=d[v*2]+d[v*2+1];
    }
    void updater(ll node, ll L, ll R, ll l, ll r, ll val){
    if (L > R || L > r || R < l)
        return;
    if (L == R){
        d[node] /= val;
        return;
    }
    ll mid = (L + R) / 2;
    updater(node*2, L, mid, l, r, val);
    updater(node*2 + 1, mid + 1, R, l, r, val);
    d[node] = d[node*2] + d[node*2+1];
    }
    void update2(ll v,ll l,ll r,ll pos){
        if(pos<l||r<pos) return;
        if(l==r){
            d[v]/=k;
            return;
        }
        ll m=(l+r)>>1;
        update2(v*2,l,m,pos);
        update2(v*2+1,m+1,r,pos);
        d[v]=d[v*2]+d[v*2+1];
    }
};
ll dp[2005][2005];
int main() {
    ll n,p,q;
    cin >> n >> p >> q;
    p = min(p,n);
    q = min(q,n);
    ll a[n];
    for(ll i = 1; i <= n; i++)cin >> a[i];
    sort(a,a+n);
    ll x[2005],y[2005] ;
    ll l = 0,r = 1000000000;
    while(l < r){
        ll w = (l+r)/2;
        memset(dp,0,sizeof dp);
        for(ll i = 1, j = 1; i <= n; i++) {
            while(a[j] - a[i] < w && j <= n) ++j;
            x[i] = --j;
        }
        for(ll i = 1, j = 1; i <= n; i++) {
            while(a[j] - a[i] < w+w && j <= n) ++j;
            y[i] = --j;
        }
        x[n+1] = y[n+1] = n;
        for(ll i = 0; i <= p; i++){
            for(ll j = 0 ; j <= q; j++){
                if(i < p)dp[i+1][j] = max(dp[i+1][j],x[dp[i][j]+1]);
                if(j < q)dp[i][j+1] = max(dp[i][j+1],y[dp[i][j]+1]);
            }
        }
        if(dp[p][q]>= n){
            r = w;
        }
        else l = w+1;
    }
    cout << l;
}
# Verdict Execution time Memory Grader output
1 Correct 28 ms 31928 KB Output is correct
2 Correct 26 ms 31932 KB Output is correct
3 Incorrect 28 ms 31828 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 28 ms 31828 KB Output is correct
2 Correct 38 ms 31932 KB Output is correct
3 Correct 244 ms 31964 KB Output is correct
4 Correct 39 ms 31828 KB Output is correct
5 Correct 46 ms 31960 KB Output is correct
6 Correct 366 ms 32076 KB Output is correct
7 Correct 39 ms 31988 KB Output is correct
8 Incorrect 40 ms 31828 KB Output isn't correct
9 Halted 0 ms 0 KB -