Submission #165757

# Submission time Handle Problem Language Result Execution time Memory
165757 2019-11-28T13:11:22 Z Hideo Rice Hub (IOI11_ricehub) C++11
100 / 100
22 ms 4088 KB
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include "ricehub.h"
//#include "grader.cpp"
using namespace std;

#define ll long long

const int N = 1e5 + 7;

ll a[N], pr[N], sf[N];
int n;

ll mx;

bool solve (int l, int r){
    int mid = ((l + r) >> 1) + 1;
    ll cost = (pr[mid] - pr[l] - (a[mid] - a[l]) * 1LL * (l - 1)) + (sf[mid] - sf[r] - (a[r] - a[mid]) * 1LL * (n - r));
    return cost <= mx;
}

int besthub(int R, int L, int X[], long long B){
    n = R; mx = B;
    for (ll i = 0; i < n; i++){
        a[i + 1] = X[i];
        pr[i + 1] = pr[i] + i * (a[i + 1] - a[i]);
    }
    for (ll i = n; i >= 1; i--)
        sf[i] = sf[i + 1] + (n - i) * (a[i + 1] - a[i]);
    int l = 1, r = n + 1;
    while (r - l > 1){
        int mid = (l + r) >> 1;
        bool ans = false;
        for (int i = 1; i + mid - 1 <= n; i++)
            ans |= solve(i, i + mid - 1);
        if (ans)
            l = mid;
        else
            r = mid;
    }
    return l;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 396 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 3 ms 388 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 368 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 248 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 3 ms 504 KB Output is correct
22 Correct 3 ms 504 KB Output is correct
23 Correct 3 ms 504 KB Output is correct
24 Correct 3 ms 504 KB Output is correct
25 Correct 3 ms 508 KB Output is correct
26 Correct 3 ms 508 KB Output is correct
27 Correct 3 ms 504 KB Output is correct
28 Correct 3 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 888 KB Output is correct
2 Correct 6 ms 860 KB Output is correct
3 Correct 20 ms 3064 KB Output is correct
4 Correct 19 ms 3064 KB Output is correct
5 Correct 11 ms 2040 KB Output is correct
6 Correct 12 ms 2040 KB Output is correct
7 Correct 17 ms 3832 KB Output is correct
8 Correct 17 ms 3832 KB Output is correct
9 Correct 11 ms 2040 KB Output is correct
10 Correct 12 ms 2040 KB Output is correct
11 Correct 22 ms 4088 KB Output is correct
12 Correct 22 ms 4060 KB Output is correct
13 Correct 12 ms 2036 KB Output is correct
14 Correct 12 ms 2140 KB Output is correct
15 Correct 17 ms 3164 KB Output is correct
16 Correct 17 ms 3192 KB Output is correct
17 Correct 19 ms 3704 KB Output is correct
18 Correct 19 ms 3704 KB Output is correct
19 Correct 21 ms 3960 KB Output is correct
20 Correct 21 ms 3960 KB Output is correct