Submission #880711

# Submission time Handle Problem Language Result Execution time Memory
880711 2023-11-29T22:22:13 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=1;j<=R;j++){
            if(abs(X[i]-X[j])<=P)s+=abs(X[i]-X[j]);
            if(abs(X[i]-X[j])<=P)u++;
        }
        for(int j=1;j<=R;j++){
            if(abs(X[i]-X[j])==P+1){
                s+=abs(X[i]-X[j]);
                if(s<=B)u++;
            }
        }
        /*
        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 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 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 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 424 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 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 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 13 ms 348 KB Output is correct
23 Correct 13 ms 472 KB Output is correct
24 Correct 12 ms 460 KB Output is correct
25 Correct 12 ms 464 KB Output is correct
26 Correct 13 ms 348 KB Output is correct
27 Correct 13 ms 464 KB Output is correct
28 Correct 13 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 348 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 36 ms 468 KB Output is correct
4 Correct 47 ms 348 KB Output is correct
5 Correct 18 ms 344 KB Output is correct
6 Correct 13 ms 444 KB Output is correct
7 Correct 50 ms 348 KB Output is correct
8 Correct 50 ms 348 KB Output is correct
9 Correct 13 ms 348 KB Output is correct
10 Correct 13 ms 348 KB Output is correct
11 Correct 32 ms 348 KB Output is correct
12 Correct 32 ms 344 KB Output is correct
13 Correct 44 ms 348 KB Output is correct
14 Correct 47 ms 348 KB Output is correct
15 Correct 13 ms 348 KB Output is correct
16 Correct 13 ms 348 KB Output is correct
17 Correct 31 ms 480 KB Output is correct
18 Correct 32 ms 348 KB Output is correct
19 Correct 43 ms 344 KB Output is correct
20 Correct 48 ms 348 KB Output is correct
21 Execution timed out 1066 ms 348 KB Time limit exceeded
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1012 ms 1368 KB Time limit exceeded
2 Halted 0 ms 0 KB -