Submission #684357

# Submission time Handle Problem Language Result Execution time Memory
684357 2023-01-21T03:34:37 Z kusssso Rice Hub (IOI11_ricehub) C++17
17 / 100
61 ms 2380 KB
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e5 + 5;

ll f[N];

bool check (ll x, ll b, int l, int r, vector<ll> &a) {
    int j = upper_bound(a.begin(), a.end(), x) - a.begin();
    j = min(j, r - 1);
    ll sum = x * (j - l + 1) - (f[j] - f[l - 1]) + (f[r] - f[j]) - x * (r - j);
    // if (x == 8 && l == 2 && r == 5) {
        // cout << f[r]- f[j] << '\n';
        // cout << j + 1 << ' ' << sum << '\n';
        // cout << (sum <= b) << '\n';
    // }
    return (sum <= b);
}

bool ok (int k, ll b, int n, vector<ll> &a) {
    for (int i = k; i <= n; i++) {
        ll med = (f[i] - f[i - k]) / k;
        if (check(med, b, i - k + 1, i, a)) {
            // if (k == 4) {
                // cout << i - k + 1 << ' ' << i << '\n';
            // }
            return true;
        }
        if (check(med + 1, b, i - k + 1, i, a)) {
            // if (k == 4) {
                // cout << i - k + 1 << ' ' << i << '\n';
            // }
            return true;
        }
        if (check(med - 1, b, i - k + 1, i, a)) {
            // if (k == 4) {
                // cout << i - k + 1 << ' ' << i << ' ' << med - 1 << '\n';
            // }
            return true;
        }
    }
    return false;
}

int besthub (int r, int l, int x[], ll b) {
    vector<ll> a;
    for (int i = 0; i < r; i++) {
        f[i + 1] = f[i] + x[i];
        a.push_back(x[i]);
    }
    int ans = -1;
    int lo = 0, hi = r;
    while (lo <= hi) {
        int mid = (lo + hi) / 2;
        if (ok(mid, b, r, a)) {
            ans = mid;
            lo = mid + 1;
        }
        else {
            hi = mid - 1;
        }
    }
    return ans;
}

// signed main() {
    // ios_base::sync_with_stdio(0);
    // cin.tie(0);
//     
    // cout << besthub(5, 20, {1, 2, 10, 12, 14}, 6);
//     
    // return 0;
// }
# 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 0 ms 212 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 0 ms 212 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 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 0 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 0 ms 212 KB Output is correct
16 Correct 0 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 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Incorrect 1 ms 212 KB Output isn't correct
28 Halted 0 ms 0 KB -
# 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 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 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 0 ms 340 KB Output is correct
14 Correct 0 ms 340 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 0 ms 212 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 2 ms 456 KB Output is correct
22 Correct 2 ms 468 KB Output is correct
23 Correct 1 ms 468 KB Output is correct
24 Correct 1 ms 468 KB Output is correct
25 Correct 1 ms 468 KB Output is correct
26 Correct 1 ms 468 KB Output is correct
27 Incorrect 3 ms 468 KB Output isn't correct
28 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 26 ms 852 KB Output is correct
2 Correct 26 ms 852 KB Output is correct
3 Correct 11 ms 2380 KB Output is correct
4 Correct 11 ms 2340 KB Output is correct
5 Correct 30 ms 1360 KB Output is correct
6 Correct 33 ms 1408 KB Output is correct
7 Correct 12 ms 2380 KB Output is correct
8 Correct 9 ms 2380 KB Output is correct
9 Correct 46 ms 1360 KB Output is correct
10 Correct 52 ms 1360 KB Output is correct
11 Correct 14 ms 2336 KB Output is correct
12 Correct 12 ms 2380 KB Output is correct
13 Incorrect 61 ms 1360 KB Output isn't correct
14 Halted 0 ms 0 KB -