Submission #343324

# Submission time Handle Problem Language Result Execution time Memory
343324 2021-01-03T16:37:39 Z Aldas25 Rice Hub (IOI11_ricehub) C++14
100 / 100
21 ms 2156 KB
#include "ricehub.h"
#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define REP(n) FOR(O, 1, (n))
#define f first
#define s second
#define pb push_back
typedef long long ll;

const int MAXN = 100100;

int r, l;
int x[MAXN];
ll b;

int besthub(int R, int L, int X[], long long B)
{
    r = R;
    l = L;
    x[0]  =X[0];
    FOR(i, 1, r) x[i] = X[i-1];
    b = B;

    int ans = 1;
    int le = 1, ri = 1;
    ll sum = 0ll;
    while (le <= r) {
        if (sum <= b) ans = max(ans, ri - le);

        int mid = (le+ri-1)/2;
        if (ri <= r && sum <= b) {
            sum += abs(x[ri] - x[mid]);
            int newMid = (le+ri)/2;
            ll dx = x[newMid] - x[mid];
            ll cnt = ri-le+1;
            sum += (cnt/2) * dx;
            sum -= ((cnt+1)/2) * dx;
            ri++;
        } else {
            sum -= abs(x[le] - x[mid]);
            int newMid = (le+ri)/2;
            ll dx = x[newMid] - x[mid];
            ll cnt = ri-le-1;
            sum += (cnt/2) * dx;
            sum -= ((cnt+1)/2) * dx;
            le++;
        }

        //cout << " le = " << le << " ri = " << ri << " sum = " << sum << endl;
    }
    return ans;
}
# 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 512 KB Output is correct
4 Correct 1 ms 364 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 0 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 0 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 0 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 0 ms 364 KB Output is correct
15 Correct 0 ms 364 KB Output is correct
16 Correct 0 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 0 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 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 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 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 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 364 KB Output is correct
23 Correct 2 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 2 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 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 492 KB Output is correct
2 Correct 3 ms 620 KB Output is correct
3 Correct 17 ms 1260 KB Output is correct
4 Correct 16 ms 2156 KB Output is correct
5 Correct 10 ms 1132 KB Output is correct
6 Correct 7 ms 1132 KB Output is correct
7 Correct 14 ms 1900 KB Output is correct
8 Correct 14 ms 1900 KB Output is correct
9 Correct 8 ms 1004 KB Output is correct
10 Correct 7 ms 1004 KB Output is correct
11 Correct 21 ms 2156 KB Output is correct
12 Correct 17 ms 2156 KB Output is correct
13 Correct 8 ms 1132 KB Output is correct
14 Correct 8 ms 1132 KB Output is correct
15 Correct 12 ms 1900 KB Output is correct
16 Correct 12 ms 1772 KB Output is correct
17 Correct 14 ms 2028 KB Output is correct
18 Correct 15 ms 2048 KB Output is correct
19 Correct 17 ms 2060 KB Output is correct
20 Correct 20 ms 2028 KB Output is correct