Submission #339483

# Submission time Handle Problem Language Result Execution time Memory
339483 2020-12-25T12:42:06 Z bigDuck Rice Hub (IOI11_ricehub) C++14
100 / 100
25 ms 3124 KB
#include "ricehub.h"

#include<bits/stdc++.h>
using namespace std;
#define INIT  ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define mp make_pair
#define pb push_back
#define ft first
#define sc second
#define ll long long
#define pii pair<int, int>
#define count_bits __builtin_popcount
#define int ll

int d1[100010], d2[100010];
int x[100010], n;

int sum1(int i, int j){
    return d1[j]-d1[i]-(i)*(x[j]-x[i]);
}

int sum2(int i, int j){
    return d2[i]-d2[j]-(n-j-1)*(x[j]-x[i]);
}




int32_t besthub(int32_t R, int32_t L, int32_t X[], long long B)
{
    n=R;
    for(int i=0; i<R; i++){
        x[i]=X[i];

        if(i>0){
            d1[i]=d1[i-1]+(i)*(x[i]-x[i-1]);

        }

    }

    for(int i=R-1; i>=0; i--){

        if(i<(R-1)){
            d2[i]=d2[i+1]+(n-(i+1))*(x[i+1]-x[i]);

        }

    }

    int res=1;
    for(int i=0; i<R; i++){
        int l=0, r=R+1, m=(l+r)>>1ll;
        while(l<r){
            m=(l+r)>>1ll;
            int lt=0, rt=0;
            if( (m%2)==1){
                lt=m>>1ll; rt=m>>1ll;
            }
            else{
                rt=m>>1ll; lt=(m>>1ll)-1;
            }

            if( (lt>(i)) || (rt>(R-(i+1))) ){
                r=m; continue;
            }

            int sum=sum1(i-lt, i)+sum2(i, i+rt);

            if(sum>B){
                r=m;
            }
            else{
                l=(m+1);
            }
            m=(l+r)>>1ll;
        }
                int lt=0, rt=0;
            if( (m%2)==1){
                lt=m>>1ll; rt=m>>1ll;
            }
            else{
                rt=m>>1ll; lt=(m>>1ll)-1;
            }
        int sum=sum1(max(i-lt, 0ll), i)+sum2(i, i+rt);
        if( (sum>B) || (lt>(i)) || (rt>(R-(i+1))) ){
            m--;
        }
        res=max(res, m);

    }
    return res;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 0 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 492 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 2 ms 492 KB Output is correct
24 Correct 2 ms 492 KB Output is correct
25 Correct 2 ms 492 KB Output is correct
26 Correct 2 ms 492 KB Output is correct
27 Correct 2 ms 492 KB Output is correct
28 Correct 2 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 876 KB Output is correct
2 Correct 5 ms 876 KB Output is correct
3 Correct 25 ms 3124 KB Output is correct
4 Correct 25 ms 3052 KB Output is correct
5 Correct 11 ms 1772 KB Output is correct
6 Correct 12 ms 1772 KB Output is correct
7 Correct 23 ms 3028 KB Output is correct
8 Correct 23 ms 3052 KB Output is correct
9 Correct 11 ms 1772 KB Output is correct
10 Correct 10 ms 1772 KB Output is correct
11 Correct 25 ms 3052 KB Output is correct
12 Correct 25 ms 3052 KB Output is correct
13 Correct 11 ms 1772 KB Output is correct
14 Correct 11 ms 1772 KB Output is correct
15 Correct 19 ms 2540 KB Output is correct
16 Correct 18 ms 2412 KB Output is correct
17 Correct 24 ms 2924 KB Output is correct
18 Correct 22 ms 2796 KB Output is correct
19 Correct 24 ms 2924 KB Output is correct
20 Correct 24 ms 2924 KB Output is correct