Submission #104893

# Submission time Handle Problem Language Result Execution time Memory
104893 2019-04-09T13:29:20 Z popovicirobert Rice Hub (IOI11_ricehub) C++14
100 / 100
299 ms 2040 KB
#include "ricehub.h"
#include <bits/stdc++.h>
#define ll long long

using namespace std;

vector <ll> sp;
vector <int> x;

inline pair <ll, int> check(int dst, int R, int pos) {
    int l = 0, r = 0;
    for(int step = 1 << 16; step; step >>= 1) {
        if(l + step <= R && x[pos] - dst > x[l + step]) {
            l += step;
        }
        if(r + step <= R && x[pos] + dst >= x[r + step]) {
            r += step;
        }
    }
    pair <ll, int> ans;
    ans.first = 1LL * (pos - l) * x[pos] - (sp[pos] - sp[l]) + (sp[r] - sp[pos]) - 1LL * (r - pos) * x[pos];
    ans.second = r - l;
    return ans;
}

int besthub(int R, int L, int X[], long long B) {
    x.resize(R + 1), sp.resize(R + 1);
    for(int i = 1; i <= R; i++) {
        x[i] = X[i - 1];
        sp[i] = sp[i - 1] + x[i];
    }
    ll ans = 0;
    for(int i = 1; i <= R; i++) {
        int dst = 0;
        for(int step = 1 << 29; step; step >>= 1) {
            if(check(dst + step, R, i).first < B) {
                dst += step;
            }
        }
        auto cur = check(dst, R, i);
        dst++;
        ans = max(ans, cur.second + (B - cur.first) / dst);
        //cerr << i << " " << cur.first << " " << cur.second << " " << dst << "\n";
    }
    ans = min(ans, 1LL * R);
    return (int) ans;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 3 ms 256 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 3 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 384 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 2 ms 256 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
19 Correct 3 ms 256 KB Output is correct
20 Correct 3 ms 384 KB Output is correct
21 Correct 3 ms 256 KB Output is correct
22 Correct 3 ms 256 KB Output is correct
23 Correct 3 ms 384 KB Output is correct
24 Correct 2 ms 384 KB Output is correct
25 Correct 3 ms 256 KB Output is correct
26 Correct 2 ms 256 KB Output is correct
27 Correct 3 ms 256 KB Output is correct
28 Correct 3 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 356 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 4 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 4 ms 428 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 4 ms 384 KB Output is correct
14 Correct 4 ms 384 KB Output is correct
15 Correct 3 ms 384 KB Output is correct
16 Correct 3 ms 256 KB Output is correct
17 Correct 3 ms 384 KB Output is correct
18 Correct 3 ms 384 KB Output is correct
19 Correct 4 ms 384 KB Output is correct
20 Correct 4 ms 300 KB Output is correct
21 Correct 10 ms 384 KB Output is correct
22 Correct 11 ms 412 KB Output is correct
23 Correct 12 ms 500 KB Output is correct
24 Correct 11 ms 496 KB Output is correct
25 Correct 10 ms 384 KB Output is correct
26 Correct 10 ms 384 KB Output is correct
27 Correct 12 ms 384 KB Output is correct
28 Correct 13 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 40 ms 688 KB Output is correct
2 Correct 43 ms 760 KB Output is correct
3 Correct 288 ms 1920 KB Output is correct
4 Correct 280 ms 2040 KB Output is correct
5 Correct 127 ms 1152 KB Output is correct
6 Correct 120 ms 1152 KB Output is correct
7 Correct 289 ms 1920 KB Output is correct
8 Correct 295 ms 1940 KB Output is correct
9 Correct 124 ms 1192 KB Output is correct
10 Correct 119 ms 1152 KB Output is correct
11 Correct 299 ms 1920 KB Output is correct
12 Correct 279 ms 1912 KB Output is correct
13 Correct 121 ms 1272 KB Output is correct
14 Correct 122 ms 1152 KB Output is correct
15 Correct 173 ms 1540 KB Output is correct
16 Correct 190 ms 1456 KB Output is correct
17 Correct 271 ms 1912 KB Output is correct
18 Correct 242 ms 1784 KB Output is correct
19 Correct 292 ms 1784 KB Output is correct
20 Correct 262 ms 1912 KB Output is correct