Submission #861244

# Submission time Handle Problem Language Result Execution time Memory
861244 2023-10-15T17:16:07 Z sleepntsheep Rice Hub (IOI11_ricehub) C++17
100 / 100
27 ms 3676 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <deque>
#include <set>
#include <utility>
#include <array>
#include "ricehub.h"

using namespace std;
#define ALL(x) x.begin(), x.end()
#define N 100005
using ll = long long;

int n, l, z = -1;
ll b, p[N], a[N];

int optimal_hub(int l, int r)
{
    return (l+r)/2;
}

ll sum(int l, int r)
{
    return p[r] - p[l-1];
}

ll need_budget(int l, int r, int h)
{
    if (h < l || r < h) return 1e18;
    return a[h] * (h-l+1) - a[h] * (r-h) + sum(h+1, r) - sum(l, h);
}

ll need_budget(int l, int r)
{
    return min({need_budget(l, r, optimal_hub(l, r)),
            need_budget(l, r, optimal_hub(l, r) + 1), 
            need_budget(l, r, optimal_hub(l, r) - 1)});
}

int besthub(int n, int l, int *a_, ll b)
{
    ::b = b; ::n = n;
    for (int i = 1;i  <=n; ++i) a[i]=a_[i-1];
    for (int i = 1; i <= n; ++i) 
    {
        p[i] = p[i-1] + a[i];
        int l = 1, r = i;
        while (l <= r)
        {
            int y = (l+r)/2;
            if (need_budget(y, i) <= b)
                z = max(z, i-y+1), r = y - 1;
            else l = y + 1;
        }
    }
    return z;
}


# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 0 ms 2488 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2392 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 0 ms 2392 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 1 ms 2392 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 0 ms 2396 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2492 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Correct 1 ms 2396 KB Output is correct
28 Correct 1 ms 2392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2492 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2460 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2392 KB Output is correct
21 Correct 1 ms 2396 KB Output is correct
22 Correct 1 ms 2396 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 2 ms 2396 KB Output is correct
25 Correct 1 ms 2532 KB Output is correct
26 Correct 2 ms 2500 KB Output is correct
27 Correct 2 ms 2392 KB Output is correct
28 Correct 2 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2652 KB Output is correct
2 Correct 5 ms 2648 KB Output is correct
3 Correct 23 ms 3500 KB Output is correct
4 Correct 23 ms 3676 KB Output is correct
5 Correct 11 ms 2908 KB Output is correct
6 Correct 11 ms 2908 KB Output is correct
7 Correct 22 ms 3440 KB Output is correct
8 Correct 22 ms 3420 KB Output is correct
9 Correct 14 ms 3164 KB Output is correct
10 Correct 11 ms 2908 KB Output is correct
11 Correct 27 ms 3500 KB Output is correct
12 Correct 23 ms 3676 KB Output is correct
13 Correct 11 ms 2908 KB Output is correct
14 Correct 10 ms 3056 KB Output is correct
15 Correct 17 ms 3420 KB Output is correct
16 Correct 22 ms 3416 KB Output is correct
17 Correct 21 ms 3500 KB Output is correct
18 Correct 21 ms 3420 KB Output is correct
19 Correct 27 ms 3416 KB Output is correct
20 Correct 22 ms 3500 KB Output is correct