Submission #494560

# Submission time Handle Problem Language Result Execution time Memory
494560 2021-12-15T17:37:11 Z Alexandruabcde Rice Hub (IOI11_ricehub) C++14
0 / 100
24 ms 2936 KB
#include "ricehub.h"
#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
constexpr int NMAX = 1e5 + 5;

int N;
int LgMax;

LL sp[NMAX];
int V[NMAX];
LL Budget;

LL Sum (int st, int dr, int j) {
    LL ans = sp[dr] + sp[st-1] - 2 * sp[j];
    LL semn = (2 * j + 2 - 2 * st - (dr - st + 1));

    if (semn < 0) return ans + 1LL * (V[j+1]-1) * semn;

    return ans + 1LL * V[j] * semn;
}

bool Check (int K) {
    int j = 1;
    LL Min = Sum(1, K, 1);
    LL val;

    for (; j <= K; ++ j )
        if ((val = Sum(1, K, j)) <= Min) Min = val;

    if (Min <= Budget) return 1;

    for (int l = 2; l <= N - K + 1; ++ l ) {
        int r = l + K - 1;

        while (j < r && Sum(l, r, j) < Sum(l, r, j+1)) ++ j;

        Min = Sum(l, r, j);

        if (Min <= Budget) return 1;
    }

    return 0;
}

int besthub(int R, int L, int X[], long long B)
{
    N = R, LgMax = L;
    for (int i = 1; i <= N; ++ i )
        V[i] = X[i-1];
    for (int i = 1; i <= N; ++ i )
        sp[i] = sp[i-1] + 1LL * V[i];

    Budget = B;

    int st = 1, dr = N;
    int ans = 1;
    while (st <= dr) {
        int mij = (st + dr) >> 1;

        if (Check(mij)) {
            ans = mij;
            st = mij + 1;
        }
        else dr = mij - 1;
    }

    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 304 KB Output is correct
2 Incorrect 1 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 308 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Incorrect 0 ms 204 KB Output isn't correct
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 304 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Incorrect 1 ms 204 KB Output isn't correct
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 736 KB Output is correct
2 Correct 4 ms 716 KB Output is correct
3 Correct 17 ms 2876 KB Output is correct
4 Correct 21 ms 2892 KB Output is correct
5 Correct 8 ms 1356 KB Output is correct
6 Correct 9 ms 1368 KB Output is correct
7 Correct 15 ms 2636 KB Output is correct
8 Correct 16 ms 2636 KB Output is correct
9 Correct 8 ms 1340 KB Output is correct
10 Correct 9 ms 1356 KB Output is correct
11 Correct 24 ms 2936 KB Output is correct
12 Correct 19 ms 2892 KB Output is correct
13 Incorrect 14 ms 1356 KB Output isn't correct
14 Halted 0 ms 0 KB -