Submission #895859

# Submission time Handle Problem Language Result Execution time Memory
895859 2023-12-31T00:36:57 Z vjudge1 Rice Hub (IOI11_ricehub) C++17
42 / 100
14 ms 4188 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define f first
#define s second

int n;
ll budget;
vector<ll> psum;

bool check(int rice, int a[]) {
    ll middle = (rice-1) / 2;
    ll right = (rice)/2 + middle;
    ll minb = 1e9;
    
    for (int i = 0; i <= n - rice; i++) {
        ll b = abs((right - middle) * (a[i+middle]) - (psum[i+right+1] - psum[i+middle+1]));
        //cout << "b1: " << b << endl;
        b += abs((middle) * a[i+middle] - (psum[i+middle] - psum[i]));
        minb = min(b, minb);
        //cout << "b: " << b << endl;
    }
    //cout << "minb: " << minb << endl;
    if (minb <= budget) return true;
    return false;
}


int besthub(int ri, int maxcoor, int a[], ll b) {
    n = ri;
    budget = b;
    ll diff[n-1];
    for (int i = 0; i < n-1; i++) {
        diff[i] = (ll)(a[i+1] - a[i]);
    }
    psum.resize(n+1);

    for (int i = 1; i <= n; i++) {
        psum[i] = a[i-1] + psum[i-1];
    }

    // for (int i = 0; i < n; i++) cout << psum[i] << " ";
    // cout << endl;
    // for (int i = 0; i < n; i++) cout << ssum[i] << " ";
    // cout << endl;
    
    ll l = 1, r = (ll)n;
    while (l < r) {
        ll mid = (l + r + 1) / 2;
        //cout << "mid: " << mid << endl;
        if (check(mid, a)) {
            l = mid;
        }
        else {
            r = mid - 1;
        }
    }
    return l;
}

// signed main() {
//     int r, l; ll b; cin >> r >> l >> b;
//     int x[r];
//     for (int i = 0; i < r; i++) cin >> x[i];
//     cout << besthub(r, l, x, b) << endl;
// }

Compilation message

ricehub.cpp: In function 'int besthub(int, int, int*, ll)':
ricehub.cpp:33:8: warning: variable 'diff' set but not used [-Wunused-but-set-variable]
   33 |     ll diff[n-1];
      |        ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 760 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 356 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 600 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 344 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Incorrect 1 ms 348 KB Output isn't correct
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 600 KB Output is correct
2 Correct 2 ms 604 KB Output is correct
3 Correct 14 ms 4184 KB Output is correct
4 Incorrect 10 ms 4188 KB Output isn't correct
5 Halted 0 ms 0 KB -