Submission #655695

# Submission time Handle Problem Language Result Execution time Memory
655695 2022-11-05T10:25:40 Z benjaminkleyn Rice Hub (IOI11_ricehub) C++17
100 / 100
117 ms 2364 KB
#include <bits/stdc++.h>
#include "ricehub.h"
using namespace std;
typedef long long ll;

ll pref[100001], x[100000];

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

ll cost(int l, int r, int i)
{
    return sum(i + 1, r) + x[i] * (2 * i - l - r) - sum(l, i - 1);
}

ll find_min(int l, int r)
{
    int lo = l, hi = r;
    while (hi - lo >= 3)
    {
        int m1 = lo + (hi - lo) / 3;
        int m2 = hi - (hi - lo) / 3;
        if (cost(l, r, m1) < cost(l, r, m2))
            hi = m2 - 1;
        else
            lo = m1;
    }
    for (int i = lo + 1; i <= hi; i++)
        if (cost(l, r, i) < cost(l, r, lo))
            lo = i;
    return cost(l, r, lo);
}

ll calc(int R, int X[], int cnt)
{
    ll mn = LLONG_MAX;
    for (int l = 0, r = cnt - 1; r < R; l++, r++)
        mn = min(mn, find_min(l, r));
    return mn;
}

int besthub(int R, int L, int X[], ll B) 
{
    for (int i = 0; i < R; i++)
        x[i] = X[i], pref[i + 1] = pref[i] + X[i];

    int lo = 0, hi = R;
    while (lo < hi)
    {
        int mid = (lo + hi + 1) / 2;

        if (calc(R, X, mid) <= B)
            lo = mid;
        else hi = mid - 1;
    }
    return lo;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 304 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 312 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 300 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 304 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 276 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 308 KB Output is correct
10 Correct 1 ms 304 KB Output is correct
11 Correct 1 ms 316 KB Output is correct
12 Correct 1 ms 360 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 308 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 7 ms 340 KB Output is correct
22 Correct 6 ms 344 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 2 ms 340 KB Output is correct
25 Correct 2 ms 444 KB Output is correct
26 Correct 2 ms 340 KB Output is correct
27 Correct 3 ms 340 KB Output is correct
28 Correct 3 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 808 KB Output is correct
2 Correct 23 ms 816 KB Output is correct
3 Correct 31 ms 2276 KB Output is correct
4 Correct 31 ms 2252 KB Output is correct
5 Correct 81 ms 1348 KB Output is correct
6 Correct 78 ms 1364 KB Output is correct
7 Correct 35 ms 2260 KB Output is correct
8 Correct 31 ms 2364 KB Output is correct
9 Correct 116 ms 1404 KB Output is correct
10 Correct 117 ms 1400 KB Output is correct
11 Correct 31 ms 2252 KB Output is correct
12 Correct 34 ms 2316 KB Output is correct
13 Correct 79 ms 1400 KB Output is correct
14 Correct 76 ms 1332 KB Output is correct
15 Correct 22 ms 1880 KB Output is correct
16 Correct 23 ms 1880 KB Output is correct
17 Correct 29 ms 2124 KB Output is correct
18 Correct 27 ms 2180 KB Output is correct
19 Correct 28 ms 2240 KB Output is correct
20 Correct 29 ms 2260 KB Output is correct