Submission #961050

# Submission time Handle Problem Language Result Execution time Memory
961050 2024-04-11T12:52:08 Z raul2008487 Rice Hub (IOI11_ricehub) C++17
100 / 100
16 ms 5268 KB
#include <bits/stdc++.h>
#include "ricehub.h"
#define ll long long
#define pb push_back
#define eb emplace_back
#define vl vector<ll>
#define fi first
#define se second
#define mpr make_pair
#define lg(x) __lg(x)
#define bpc(x) __builtin_popcount(x)
#define all(v) v.begin(), v.end()
#define endl "\n"
using namespace std;
int besthub(int R, int L, int X[], long long B)
{
    ll lo = 1, hi = R, mid, best = 1, sum, i, j, n = R, left, right, x;
    vl pr(n), sf(n);
    pr[0] = X[0];
    sf[n - 1] = X[n - 1];
    for(i = 1; i  < n; i++){
        pr[i] = pr[i - 1] + X[i];
    }
    for(i = n - 2; i >= 0; i--){
        sf[i] = sf[i + 1] + X[i];
    }
    lo = 1, hi = R;
    while(lo <= hi){
        mid = (lo + hi) >> 1;
        if(mid == 1){break;}
        bool ok = 0;
        for(i = 0; i < n - mid + 1; i++){
            if(mid & 1){
                left = right = i + (mid / 2);
                x = X[left];
            }
            else{
                left = i + (mid / 2)  - 1;
                right = left + 1;
                x = (X[right] + X[left]) / 2;
            }
            sum = ((left - i + 1) * x) - pr[left];
            if(i){sum += pr[i - 1];}
            sum += pr[i + mid - 1] - pr[right - 1] - (((i + mid - 1) - right + 1) * x);
            ok |= (sum <= B);
        }
        if(ok){
            best = mid;
            lo = mid + 1;
        }
        else{
            hi = mid - 1;
        }
    }
    return best;
}

Compilation message

ricehub.cpp: In function 'int besthub(int, int, int*, long long int)':
ricehub.cpp:17:47: warning: unused variable 'j' [-Wunused-variable]
   17 |     ll lo = 1, hi = R, mid, best = 1, sum, i, j, n = R, left, right, x;
      |                                               ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 412 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 344 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 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 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 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 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 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 452 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 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 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 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 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 972 KB Output is correct
2 Correct 3 ms 972 KB Output is correct
3 Correct 10 ms 5212 KB Output is correct
4 Correct 16 ms 5268 KB Output is correct
5 Correct 6 ms 3676 KB Output is correct
6 Correct 7 ms 3676 KB Output is correct
7 Correct 9 ms 5208 KB Output is correct
8 Correct 9 ms 4956 KB Output is correct
9 Correct 6 ms 3532 KB Output is correct
10 Correct 6 ms 3644 KB Output is correct
11 Correct 10 ms 5212 KB Output is correct
12 Correct 10 ms 5092 KB Output is correct
13 Correct 7 ms 3676 KB Output is correct
14 Correct 6 ms 3676 KB Output is correct
15 Correct 8 ms 4628 KB Output is correct
16 Correct 8 ms 4480 KB Output is correct
17 Correct 9 ms 4956 KB Output is correct
18 Correct 10 ms 4956 KB Output is correct
19 Correct 10 ms 4956 KB Output is correct
20 Correct 10 ms 4956 KB Output is correct