Submission #530809

# Submission time Handle Problem Language Result Execution time Memory
530809 2022-02-26T20:51:22 Z SlavicG Rice Hub (IOI11_ricehub) C++17
100 / 100
16 ms 2960 KB
#include "bits/stdc++.h"
#include "ricehub.h"
using namespace std;
 
#define ll long long
 
#define       forn(i,n)              for(int i=0;i<n;i++)
#define          all(v)              v.begin(), v.end()
#define         rall(v)              v.rbegin(),v.rend()
 
#define            pb                push_back
#define          sz(a)               (int)a.size()


ll query(int l, int r, vector<ll>& p) {
    return p[r] - (l ? p[l - 1] : 0);
}

bool ok(int val, vector<int>& x, ll b) {
    int n = sz(x);
    vector<ll> p(n);
    for(int i = 0;i < n; ++i) {
        p[i] = (i ? p[i - 1] : 0) + x[i];
    }

    for(int i = 0; i + val - 1 < n; ++i) {
        ll med = (i + val / 2);
        ll calc = 1LL * x[med] * (i + val / 2 - i + 1) - query(i, i + val / 2, p);
        if(calc > b) continue;
        calc += 1LL * query(i + val / 2, i + val - 1, p) - 1LL * x[med] * (i + val - 1 - i - val / 2 + 1);
        if(calc <= b) return true;
    }
    return false;
}

int besthub(int R, int L, int f[], ll b) {
    int l = 1, r = R, ans = 0;
    vector<int> x;
    for(int i = 0;i < R; ++i) x.pb(f[i]);
    while(l <= r) {
        int mid = l + r >> 1;
        if(ok(mid, x, b)) {
            ans = mid;
            l = mid + 1;
        } else r = mid - 1;
    }

    return ans;
}

/*
void solve() {
    int r, l; ll b;
    cin >> r >> l >> b;
    vector<int> x(r);
    forn(i, r) cin >> x[i];

    cout << besthub(r, l, x, b) << "\n";
} 
 
int32_t main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t = 1;
    //cin >> t;
    while(t--) {
        solve();
    }
}
*/

Compilation message

ricehub.cpp: In function 'int besthub(int, int, int*, long long int)':
ricehub.cpp:41:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   41 |         int mid = l + r >> 1;
      |                   ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 0 ms 204 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
25 Correct 0 ms 204 KB Output is correct
26 Correct 0 ms 204 KB Output is correct
27 Correct 0 ms 204 KB Output is correct
28 Correct 0 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 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 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 1 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 0 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 332 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 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 716 KB Output is correct
2 Correct 3 ms 716 KB Output is correct
3 Correct 13 ms 1988 KB Output is correct
4 Correct 12 ms 1920 KB Output is correct
5 Correct 6 ms 1516 KB Output is correct
6 Correct 6 ms 1480 KB Output is correct
7 Correct 12 ms 2748 KB Output is correct
8 Correct 12 ms 2716 KB Output is correct
9 Correct 6 ms 1488 KB Output is correct
10 Correct 7 ms 1452 KB Output is correct
11 Correct 13 ms 2960 KB Output is correct
12 Correct 13 ms 2960 KB Output is correct
13 Correct 7 ms 1480 KB Output is correct
14 Correct 7 ms 1488 KB Output is correct
15 Correct 10 ms 2360 KB Output is correct
16 Correct 10 ms 2388 KB Output is correct
17 Correct 12 ms 2732 KB Output is correct
18 Correct 11 ms 2700 KB Output is correct
19 Correct 16 ms 2832 KB Output is correct
20 Correct 12 ms 2856 KB Output is correct