Submission #308148

# Submission time Handle Problem Language Result Execution time Memory
308148 2020-09-30T06:09:49 Z talant117408 Rice Hub (IOI11_ricehub) C++17
100 / 100
20 ms 3104 KB
#include "ricehub.h"

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair <int, int> pii;

#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()

const int N = 1e5+7;
vector <ll> pref(N), suff(N), v(N);
int n;

ll getpref(int l, int r){
    return pref[r]-1ll*(l-1)*(v[r]-v[l-1])-pref[l-1];
}

ll getsuff(int l, int r){
    return suff[l]-1ll*(n-r)*(v[r+1]-v[l])-suff[r+1];
}

bool check2(int l, int r, ll B){
    int mid = (l+r) >> 1;
    return getpref(l, mid)+getsuff(mid, r) <= B;
}

bool check(int x, ll B){
    int flag = 0;
    for(int i = 1; i+x-1 <= n; i++){
        if(check2(i, i+x-1, B)){
            flag++;
            break;
        }
    }
    return flag;
}

int besthub(int R, int L, int X[], long long B){
    n = R;
    int i;
    for(i = 0; i < R; i++){
        v[i+1] = X[i];
    }
    for(i = 1; i <= n; i++){
        pref[i] = pref[i-1]+1ll*(i-1)*(v[i]-v[i-1]);
    }
    for(i = n; i; i--){
        suff[i] = suff[i+1]+1ll*(n-i)*(v[i+1]-v[i]);
    }
    
    int l = 1, r = n;
    while(l < r){
        int mid = (l+r+1) >> 1;
        if(check(mid, B)) l = mid;
        else r = mid-1;
    }
    
    return l;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Correct 2 ms 2688 KB Output is correct
3 Correct 2 ms 2688 KB Output is correct
4 Correct 2 ms 2688 KB Output is correct
5 Correct 2 ms 2688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Correct 2 ms 2688 KB Output is correct
3 Correct 2 ms 2688 KB Output is correct
4 Correct 2 ms 2688 KB Output is correct
5 Correct 2 ms 2688 KB Output is correct
6 Correct 2 ms 2688 KB Output is correct
7 Correct 2 ms 2688 KB Output is correct
8 Correct 2 ms 2688 KB Output is correct
9 Correct 2 ms 2688 KB Output is correct
10 Correct 2 ms 2688 KB Output is correct
11 Correct 2 ms 2688 KB Output is correct
12 Correct 2 ms 2688 KB Output is correct
13 Correct 2 ms 2688 KB Output is correct
14 Correct 2 ms 2688 KB Output is correct
15 Correct 2 ms 2688 KB Output is correct
16 Correct 2 ms 2688 KB Output is correct
17 Correct 2 ms 2688 KB Output is correct
18 Correct 2 ms 2688 KB Output is correct
19 Correct 2 ms 2720 KB Output is correct
20 Correct 2 ms 2688 KB Output is correct
21 Correct 2 ms 2688 KB Output is correct
22 Correct 2 ms 2688 KB Output is correct
23 Correct 2 ms 2688 KB Output is correct
24 Correct 2 ms 2688 KB Output is correct
25 Correct 2 ms 2688 KB Output is correct
26 Correct 2 ms 2688 KB Output is correct
27 Correct 2 ms 2688 KB Output is correct
28 Correct 2 ms 2688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Correct 2 ms 2688 KB Output is correct
3 Correct 2 ms 2688 KB Output is correct
4 Correct 2 ms 2688 KB Output is correct
5 Correct 2 ms 2688 KB Output is correct
6 Correct 2 ms 2688 KB Output is correct
7 Correct 2 ms 2688 KB Output is correct
8 Correct 2 ms 2688 KB Output is correct
9 Correct 2 ms 2688 KB Output is correct
10 Correct 2 ms 2688 KB Output is correct
11 Correct 2 ms 2688 KB Output is correct
12 Correct 2 ms 2688 KB Output is correct
13 Correct 2 ms 2688 KB Output is correct
14 Correct 2 ms 2688 KB Output is correct
15 Correct 2 ms 2688 KB Output is correct
16 Correct 2 ms 2688 KB Output is correct
17 Correct 2 ms 2688 KB Output is correct
18 Correct 2 ms 2688 KB Output is correct
19 Correct 2 ms 2688 KB Output is correct
20 Correct 3 ms 2720 KB Output is correct
21 Correct 2 ms 2688 KB Output is correct
22 Correct 3 ms 2688 KB Output is correct
23 Correct 2 ms 2688 KB Output is correct
24 Correct 2 ms 2688 KB Output is correct
25 Correct 2 ms 2688 KB Output is correct
26 Correct 3 ms 2688 KB Output is correct
27 Correct 3 ms 2688 KB Output is correct
28 Correct 3 ms 2688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 2816 KB Output is correct
2 Correct 7 ms 2816 KB Output is correct
3 Correct 19 ms 3072 KB Output is correct
4 Correct 19 ms 3072 KB Output is correct
5 Correct 11 ms 2816 KB Output is correct
6 Correct 11 ms 2816 KB Output is correct
7 Correct 16 ms 3072 KB Output is correct
8 Correct 15 ms 3072 KB Output is correct
9 Correct 10 ms 2816 KB Output is correct
10 Correct 10 ms 2816 KB Output is correct
11 Correct 20 ms 3064 KB Output is correct
12 Correct 18 ms 3072 KB Output is correct
13 Correct 11 ms 2944 KB Output is correct
14 Correct 11 ms 2816 KB Output is correct
15 Correct 15 ms 2944 KB Output is correct
16 Correct 15 ms 2944 KB Output is correct
17 Correct 17 ms 3072 KB Output is correct
18 Correct 17 ms 3072 KB Output is correct
19 Correct 18 ms 3104 KB Output is correct
20 Correct 19 ms 3072 KB Output is correct