Submission #296645

# Submission time Handle Problem Language Result Execution time Memory
296645 2020-09-10T17:55:37 Z alexandra_udristoiu Rice Hub (IOI11_ricehub) C++14
100 / 100
28 ms 2944 KB
#include "ricehub.h"
#include<algorithm>
#define DIM 100005
using namespace std;

static int v[DIM], n;
static long long sum[DIM];
long long calc(int p, int u, int i){
    return ( sum[u] - sum[i] - v[i] * 1LL * (u - i) ) + ( (i - p + 1) * 1LL * v[i] - sum[i] + sum[p - 1]);
}
long long solve(int k){
    int i, p;
    long long minim = 100000000000000LL;
    p = 1;
    for(i = 1; i <= n - k + 1; i++){
        p = max(p, i);
        while(p < i + k - 1 && calc(i, i + k - 1, p + 1) <= calc(i, i + k - 1, p) ){
            p++;
        }
        minim = min(minim, calc(i, i + k - 1, p) );
    }
    return minim;
}

int besthub(int N, int m, int X[], long long b){
    int i, st, dr, mid;
    n = N;
    for(i = 1; i <= n; i++){
        v[i] = X[i - 1];
        sum[i] = sum[i - 1] + v[i];
    }
    st = 1;
    dr = n;
    while(st <= dr){
        mid = (st + dr) / 2;
        if( solve(mid) <= b ){
            st = mid + 1;
        }
        else{
            dr = mid - 1;
        }
    }
    return dr;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 320 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 1 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 0 ms 256 KB Output is correct
8 Correct 1 ms 256 KB Output is correct
9 Correct 0 ms 320 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 0 ms 256 KB Output is correct
12 Correct 0 ms 256 KB Output is correct
13 Correct 1 ms 256 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 0 ms 256 KB Output is correct
16 Correct 1 ms 256 KB Output is correct
17 Correct 0 ms 256 KB Output is correct
18 Correct 0 ms 256 KB Output is correct
19 Correct 0 ms 256 KB Output is correct
20 Correct 0 ms 256 KB Output is correct
21 Correct 1 ms 256 KB Output is correct
22 Correct 1 ms 360 KB Output is correct
23 Correct 1 ms 256 KB Output is correct
24 Correct 1 ms 256 KB Output is correct
25 Correct 1 ms 256 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 0 ms 256 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 1 ms 260 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 1 ms 256 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 0 ms 256 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 2 ms 384 KB Output is correct
22 Correct 2 ms 384 KB Output is correct
23 Correct 1 ms 404 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 2 ms 404 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 768 KB Output is correct
2 Correct 6 ms 768 KB Output is correct
3 Correct 27 ms 2936 KB Output is correct
4 Correct 28 ms 2944 KB Output is correct
5 Correct 15 ms 1408 KB Output is correct
6 Correct 15 ms 1408 KB Output is correct
7 Correct 18 ms 2688 KB Output is correct
8 Correct 18 ms 2688 KB Output is correct
9 Correct 17 ms 1408 KB Output is correct
10 Correct 15 ms 1408 KB Output is correct
11 Correct 22 ms 2944 KB Output is correct
12 Correct 22 ms 2936 KB Output is correct
13 Correct 17 ms 1532 KB Output is correct
14 Correct 21 ms 1536 KB Output is correct
15 Correct 16 ms 2304 KB Output is correct
16 Correct 26 ms 2304 KB Output is correct
17 Correct 20 ms 2688 KB Output is correct
18 Correct 25 ms 2688 KB Output is correct
19 Correct 21 ms 2816 KB Output is correct
20 Correct 28 ms 2816 KB Output is correct