Submission #494564

# Submission time Handle Problem Language Result Execution time Memory
494564 2021-12-15T17:50:15 Z Alexandruabcde Rice Hub (IOI11_ricehub) C++14
100 / 100
18 ms 2764 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 BruteCheck (int K) {
    for (int l = 1; l <= N - K + 1; ++ l ) {
        int r = l + K - 1;
        int j = l;
        for (int P = V[l]; P <= V[r]; ++ P ) {
            while (j <= r && V[j] <= P) ++ j;
            -- j;

            LL val = P * (2 * j + 2 - 2 * l - K) - 2 * sp[j] + sp[l-1] + sp[r];

            if (val <= Budget)
            {
                cout << l << " " << r << " " << P << '\n';
                return 1;
            }
        }
    }

    return 0;
}

bool Check (int K) {
    int j = 1;

    while (j < K && Sum(1, K, j) > Sum(1, K, j+1)) ++ j;

    if (Sum(1, K, j) <= 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;

        LL 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 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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 0 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 1 ms 300 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 0 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 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 296 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
# 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 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 1 ms 204 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 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 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 300 KB Output is correct
17 Correct 1 ms 304 KB Output is correct
18 Correct 0 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 2 ms 332 KB Output is correct
23 Correct 2 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 716 KB Output is correct
2 Correct 4 ms 716 KB Output is correct
3 Correct 15 ms 2136 KB Output is correct
4 Correct 16 ms 2232 KB Output is correct
5 Correct 10 ms 1320 KB Output is correct
6 Correct 10 ms 1432 KB Output is correct
7 Correct 17 ms 2252 KB Output is correct
8 Correct 15 ms 2148 KB Output is correct
9 Correct 10 ms 1320 KB Output is correct
10 Correct 10 ms 1356 KB Output is correct
11 Correct 17 ms 2204 KB Output is correct
12 Correct 18 ms 2124 KB Output is correct
13 Correct 12 ms 1476 KB Output is correct
14 Correct 14 ms 1376 KB Output is correct
15 Correct 13 ms 2252 KB Output is correct
16 Correct 12 ms 2220 KB Output is correct
17 Correct 15 ms 2596 KB Output is correct
18 Correct 14 ms 2636 KB Output is correct
19 Correct 14 ms 2764 KB Output is correct
20 Correct 17 ms 2692 KB Output is correct