Submission #956968

# Submission time Handle Problem Language Result Execution time Memory
956968 2024-04-02T18:14:44 Z Nelt Rice Hub (IOI11_ricehub) C++17
100 / 100
17 ms 4444 KB
#include "ricehub.h"
#include <bits/stdc++.h>

#define ll long long
#define endl "\n"
using namespace std;

int besthub(int n, int L, int x[], long long B)
{
    ll ans = 0, pref[n];
    for (ll i = 0; i < n; i++)
        pref[i] = (i - 1 >= 0 ? pref[i - 1] : 0) + x[i];
    auto sum = [&](ll l, ll r)
    {
        return pref[r] - (l - 1 >= 0 ? pref[l - 1] : 0);
    };
    auto best = [&](ll l, ll r)
    {
        ll lo = l, hi = r - 1, mid, ans = x[r] * (r - l + 1) - sum(l, r);
        while (lo <= hi)
        {
            mid = (lo + hi) >> 1;
            ans = min({ans, x[mid] * (mid - l + 1) - x[mid] * (r - mid) + sum(mid + 1, r) - sum(l, mid), x[mid + 1] * (mid + 1 - l + 1) - x[mid + 1] * (r - (mid + 1)) + sum(mid + 2, r) - sum(l, mid + 1)});
            if (x[mid] * (mid - l + 1) - x[mid] * (r - mid) + sum(mid + 1, r) - sum(l, mid) < x[mid + 1] * (mid + 1 - l + 1) - x[mid + 1] * (r - (mid + 1)) + sum(mid + 2, r) - sum(l, mid + 1))
                lo = mid + 1;
            else
                hi = mid - 1;
        }
        return ans;
    };
    for (ll i = 0, j = 0; i < n; i++)
    {
        while (best(j, i) > B)
            j++;
        ans = max(ans, i - j + 1);
    }
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 452 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 440 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 600 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 356 KB Output is correct
26 Correct 1 ms 352 KB Output is correct
27 Correct 0 ms 352 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 352 KB Output is correct
2 Correct 0 ms 352 KB Output is correct
3 Correct 0 ms 448 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 600 KB Output is correct
6 Correct 0 ms 352 KB Output is correct
7 Correct 0 ms 452 KB Output is correct
8 Correct 0 ms 352 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 600 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 676 KB Output is correct
2 Correct 3 ms 604 KB Output is correct
3 Correct 15 ms 4444 KB Output is correct
4 Correct 15 ms 4444 KB Output is correct
5 Correct 7 ms 3160 KB Output is correct
6 Correct 7 ms 3160 KB Output is correct
7 Correct 13 ms 4188 KB Output is correct
8 Correct 13 ms 4056 KB Output is correct
9 Correct 8 ms 3164 KB Output is correct
10 Correct 8 ms 3164 KB Output is correct
11 Correct 14 ms 4308 KB Output is correct
12 Correct 14 ms 4280 KB Output is correct
13 Correct 7 ms 3420 KB Output is correct
14 Correct 7 ms 3420 KB Output is correct
15 Correct 13 ms 3932 KB Output is correct
16 Correct 11 ms 3932 KB Output is correct
17 Correct 13 ms 4288 KB Output is correct
18 Correct 17 ms 4188 KB Output is correct
19 Correct 14 ms 4188 KB Output is correct
20 Correct 13 ms 4188 KB Output is correct