Submission #655692

# Submission time Handle Problem Language Result Execution time Memory
655692 2022-11-05T10:19:58 Z benjaminkleyn Rice Hub (IOI11_ricehub) C++17
68 / 100
1000 ms 2132 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 calc(int R, int X[], int cnt)
{
    ll mn = LLONG_MAX;
    for (int l = 0, r = cnt - 1; r < R; l++, r++)
        for (int i = l; i <= r; i++)
            mn = min(mn, cost(l, r, i));
    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 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 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 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 2 ms 328 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 2 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 212 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 2 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 2 ms 324 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 2 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 2 ms 340 KB Output is correct
21 Correct 28 ms 460 KB Output is correct
22 Correct 33 ms 404 KB Output is correct
23 Correct 24 ms 412 KB Output is correct
24 Correct 20 ms 416 KB Output is correct
25 Correct 25 ms 412 KB Output is correct
26 Correct 29 ms 340 KB Output is correct
27 Correct 100 ms 396 KB Output is correct
28 Correct 81 ms 392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 343 ms 716 KB Output is correct
2 Correct 324 ms 684 KB Output is correct
3 Execution timed out 1067 ms 2132 KB Time limit exceeded
4 Halted 0 ms 0 KB -