Submission #880716

# Submission time Handle Problem Language Result Execution time Memory
880716 2023-11-29T22:33:56 Z andro Rice Hub (IOI11_ricehub) C++14
42 / 100
1000 ms 1368 KB
#include <bits/stdc++.h>
#include "ricehub.h"
//#define int long long
using namespace std;
int besthub(int R, int L, int X[], long long B){
    long long pref[R+1];
    pref[0]=0;
    for(int i=1;i<=R;i++)pref[i]=pref[i-1]+X[i];
    int ans=0;
    map<int,int>cnt;
    for(int i=1;i<=R;i++)cnt[X[i]]++;
    for(int i=1;i<=R;i++){
        long long LL=0LL,RR=(long long)1e15,P=0;
        while(LL<=RR){
            long long s=(LL+RR)/2;
            long long c=0;
            for(int j=1;j<=R;j++){
                if(X[j]>=X[i]&&X[j]<=X[i]+s){
                    c+=X[j]-X[i];
                }
                else if(X[j]<=X[i]&&X[j]>=X[i]-s&&X[j]<=X[i]){
                    c+=X[i]-X[j];
                }
            }
            /*
            int l=1,r=i,p=-1;
            while(l<=r){
                int mid=(l+r)/2;
                if(abs(X[mid]-X[i])<=s){
                    r=mid-1;
                    p=mid;
                }
                else {
                    l=mid+1;
                }
            }
            int x=i-p+1;
            c+=X[i]*x-(pref[i]-pref[p-1]);
            l=i+1,r=R,p=-1;
            while(l<=r){
                int mid=(l+r)/2;
                if(abs(X[i]-X[mid])<=s){
                    l=mid+1;
                    p=mid;
                }
                else {
                    r=mid-1;
                }
            }
            if(p!=-1){
                x=p-i;
                c+=(pref[p]-pref[i])-X[i]*x;
            }*/
            if(c<=B){
                LL=s+1;
                P=s;
            }
            else {
                RR=s-1;
            }
            //cout<<i<<" "<<s<<" "<<c;
            //cout<<endl;
        }
        int u=0;
        long long s=0;
        for(int j=i-1;j>=1;j--){
            if(abs(X[i]-X[j])>P)break;
            u++;
            s+=abs(X[i]-X[j]);
        }
        for(int j=i;j<=R;j++){
            if(abs(X[i]-X[j])>P)break;
            u++;
            s+=abs(X[i]-X[j]);
        }
        /*
        int l=1,r=i,p=-1;
        while(l<=r){
            int mid=(l+r)/2;
            if(abs(X[mid]-X[i])<=P){
                r=mid-1;
                p=mid;
            }
            else {
                l=mid+1;
            }
        }
        s+=((i-p+1)*X[i])-(pref[i]-pref[p-1]);
        u+=i-p+1;
        l=i+1,r=R,p=-1;
        while(l<=r){
            int mid=(l+r)/2;
            if(abs(X[mid]-X[i])<=P){
                l=mid+1;
                p=mid;
            }
            else {
                r=mid-1;
            }
        }
        if(p!=-1){
            u+=p-i;
            s+=(pref[p]-pref[i])-(X[i]*(p-i));
        }*/
        // |x-y|=P
        //! kolko ih ima na intervalu [a[i],a[i]+mid]+[a[i]-mid,a[i]]
        for(int j=1;j<=R;j++){
            if(abs(X[j]-X[i])==P+1){
                s+=abs(X[j]-X[i]);
                if(s<=B)u++;
            }
        }
        //cout<<i<<" "<<u<<" "<<s;
        //cout<<endl;
        ans=max(ans,u);
    }
    return ans;
}/*
signed main(){
    int X[4]={0,10,12,14};
    cout<<besthub(3,14,X,6);
}*/
/*
1 3 6
2 3 4
3 3 6
3
*/
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 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 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 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 352 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 448 KB Output is correct
7 Correct 1 ms 356 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 13 ms 348 KB Output is correct
22 Correct 14 ms 448 KB Output is correct
23 Correct 12 ms 476 KB Output is correct
24 Correct 12 ms 348 KB Output is correct
25 Correct 12 ms 348 KB Output is correct
26 Correct 12 ms 344 KB Output is correct
27 Correct 12 ms 344 KB Output is correct
28 Correct 14 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 344 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 36 ms 600 KB Output is correct
4 Correct 37 ms 356 KB Output is correct
5 Correct 13 ms 356 KB Output is correct
6 Correct 12 ms 348 KB Output is correct
7 Correct 51 ms 348 KB Output is correct
8 Correct 48 ms 348 KB Output is correct
9 Correct 12 ms 348 KB Output is correct
10 Correct 13 ms 348 KB Output is correct
11 Correct 30 ms 448 KB Output is correct
12 Correct 33 ms 348 KB Output is correct
13 Correct 38 ms 344 KB Output is correct
14 Correct 46 ms 348 KB Output is correct
15 Correct 12 ms 600 KB Output is correct
16 Correct 12 ms 348 KB Output is correct
17 Correct 27 ms 348 KB Output is correct
18 Correct 30 ms 468 KB Output is correct
19 Correct 40 ms 344 KB Output is correct
20 Correct 45 ms 348 KB Output is correct
21 Execution timed out 1043 ms 348 KB Time limit exceeded
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1028 ms 1368 KB Time limit exceeded
2 Halted 0 ms 0 KB -