Submission #521175

# Submission time Handle Problem Language Result Execution time Memory
521175 2022-02-01T07:11:22 Z Jomnoi Rice Hub (IOI11_ricehub) C++17
100 / 100
19 ms 2368 KB
#include <bits/stdc++.h>
#include "ricehub.h"
#define DEBUG 0
using namespace std;

const int N = 1e5 + 10;

int n;
long long lim;
long long x[N];

bool check(int sz) {
    int l = 1, r = sz;
    int mid = (l + r) / 2;

    int sz_l = mid - l, sz_r = r - mid;
    long long L = 0, R = 0;
    for(int i = l; i < mid; i++) {
        L += x[mid] - x[i];
    }
    for(int i = mid + 1; i <= r; i++) {
        R += x[i] - x[mid];
    }

    if(L + R <= lim) {
        return true;
    }
    while(r < n) {
        L -= x[mid] - x[l];
        R -= (x[mid + 1] - x[mid]) * sz_r;
        l++, r++, mid++;
        L += (x[mid] - x[mid - 1]) * sz_l;
        R += x[r] - x[mid];
        if(L + R <= lim) {
            return true;
        }
    }
    return false;
}

int besthub(int R, int L, int X[], long long B) {
    n = R;
    lim = B;
    for(int i = 1; i <= R; i++) {
        x[i] = X[i - 1];
    }

    int l = 1, r = R, pos = -1;
    while(l <= r) {
        int mid = (l + r) / 2;

        if(check(mid) == true) {
            pos = mid;
            l = mid + 1;
        }
        else {
            r = mid - 1;
        }
    }
    return pos;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 296 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 300 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 0 ms 204 KB Output is correct
27 Correct 2 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 1 ms 308 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 296 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 304 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 300 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 300 KB Output is correct
20 Correct 1 ms 300 KB Output is correct
21 Correct 1 ms 308 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 308 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 588 KB Output is correct
2 Correct 4 ms 588 KB Output is correct
3 Correct 15 ms 1600 KB Output is correct
4 Correct 14 ms 1484 KB Output is correct
5 Correct 6 ms 972 KB Output is correct
6 Correct 6 ms 1100 KB Output is correct
7 Correct 12 ms 1604 KB Output is correct
8 Correct 11 ms 1608 KB Output is correct
9 Correct 6 ms 1100 KB Output is correct
10 Correct 9 ms 1332 KB Output is correct
11 Correct 17 ms 1720 KB Output is correct
12 Correct 16 ms 1612 KB Output is correct
13 Correct 7 ms 1092 KB Output is correct
14 Correct 6 ms 1196 KB Output is correct
15 Correct 11 ms 1956 KB Output is correct
16 Correct 19 ms 1908 KB Output is correct
17 Correct 13 ms 2244 KB Output is correct
18 Correct 17 ms 2224 KB Output is correct
19 Correct 13 ms 2368 KB Output is correct
20 Correct 13 ms 2340 KB Output is correct