답안 #880722

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
880722 2023-11-29T22:41:00 Z andro 쌀 창고 (IOI11_ricehub) C++14
42 / 100
1000 ms 1372 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+=X[i]-X[j];
        }
        for(int j=i;j<=R;j++){
            if(abs(X[i]-X[j])>P)break;
            u++;
            s+=X[j]-X[i];
        }
        /*
        int l=1,r=i,p=-1;
        while(l<=r){
            int mid=(l+r)/2;
            if(X[i]-X[mid]<=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(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));
        }
        for(int j=1;j<=R;j++){
            if(abs(X[i]-X[j])<=P)s+=abs(X[i]-X[j]);
        }*/
        // |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
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 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
# 결과 실행 시간 메모리 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 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 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 0 ms 348 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 344 KB Output is correct
21 Correct 14 ms 348 KB Output is correct
22 Correct 12 ms 348 KB Output is correct
23 Correct 12 ms 344 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 348 KB Output is correct
27 Correct 13 ms 468 KB Output is correct
28 Correct 14 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 31 ms 492 KB Output is correct
4 Correct 37 ms 348 KB Output is correct
5 Correct 13 ms 344 KB Output is correct
6 Correct 13 ms 440 KB Output is correct
7 Correct 51 ms 344 KB Output is correct
8 Correct 55 ms 444 KB Output is correct
9 Correct 14 ms 348 KB Output is correct
10 Correct 12 ms 464 KB Output is correct
11 Correct 32 ms 348 KB Output is correct
12 Correct 37 ms 348 KB Output is correct
13 Correct 40 ms 344 KB Output is correct
14 Correct 46 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 26 ms 464 KB Output is correct
18 Correct 35 ms 348 KB Output is correct
19 Correct 38 ms 348 KB Output is correct
20 Correct 47 ms 348 KB Output is correct
21 Execution timed out 1016 ms 344 KB Time limit exceeded
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1036 ms 1372 KB Time limit exceeded
2 Halted 0 ms 0 KB -