Submission #930131

# Submission time Handle Problem Language Result Execution time Memory
930131 2024-02-18T15:55:54 Z Karoot Rice Hub (IOI11_ricehub) C++17
100 / 100
16 ms 5724 KB
#include <iostream>
#include <cmath>
#include <unordered_map>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <string>
#include <iomanip>
#include <algorithm>

#define all(x)  (x).begin(), (x).end()
#define rall(x)  (x).rbegin(), (x).rend()

using namespace std;

typedef long long ll;

ll linf = 1e15+1;

inline void scoobydoobydoo(){
    ios::sync_with_stdio(false);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
}

const int MAXN = 2e5+1;
ll farms[MAXN];
ll pref[MAXN];
ll n, nmax;
ll budget;

ll calc(ll point, ll l, ll r){
    ll howR = r-point;
    ll right = pref[r]-pref[point]-howR*farms[point];

    ll howL = point-l;
    ll left = howL*farms[point]-pref[point-1]+(l == 0 ? 0 :pref[l-1]);
    return right+left;
}

bool works(int di){
    int l = 0, r = di-1;
    ll mid = 0;
    ll mini = 1e15;
    ll lowest = 1e15;
    for (int i = 0; i <= r; i++){
        ll sum = calc(i, l, r);
        if (sum < mini){
            mini = sum;
            mid = i;
        }
    }
    lowest = min(lowest, mini);
    //cout << "low: " << lowest << " " << mid << endl;
    while (r < n-1){
        l++; r++;
        while (calc(mid+1, l, r) <= calc(mid, l, r)){
            mid++;
        }
        lowest = min(lowest, calc(mid, l, r));
        //cout << "low: " << lowest << " " << mid << endl;
    }
    
    //cout << di << " " << lowest << endl;

    return lowest <= budget;
}

int besthub(int R, int L, int X[], ll B){
    n = R;
    nmax = L+1;
    budget = B;
    for (int i = 0; i < n; i++){
        farms[i] = X[i];
        pref[i] = farms[i] + (i != 0 ? pref[i-1] : 0);
    }

    ll a = 0, b = n+1;
    ll ret = 0;
    while (a < b){
        ll k = (a+b)>>1;
        if (works(k)){
            ret = k;
            a = k+1;
        } else b = k;
    }

    return ret;
}

# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4696 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4700 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4440 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4440 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4544 KB Output is correct
22 Correct 1 ms 4440 KB Output is correct
23 Correct 1 ms 4440 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4548 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4440 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4440 KB Output is correct
8 Correct 1 ms 4440 KB Output is correct
9 Correct 2 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4440 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4528 KB Output is correct
21 Correct 2 ms 4440 KB Output is correct
22 Correct 2 ms 4444 KB Output is correct
23 Correct 1 ms 4440 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4440 KB Output is correct
26 Correct 1 ms 4576 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4952 KB Output is correct
2 Correct 4 ms 4700 KB Output is correct
3 Correct 12 ms 5548 KB Output is correct
4 Correct 12 ms 5720 KB Output is correct
5 Correct 10 ms 5036 KB Output is correct
6 Correct 9 ms 5052 KB Output is correct
7 Correct 16 ms 5468 KB Output is correct
8 Correct 11 ms 5720 KB Output is correct
9 Correct 9 ms 4952 KB Output is correct
10 Correct 9 ms 4956 KB Output is correct
11 Correct 12 ms 5724 KB Output is correct
12 Correct 13 ms 5608 KB Output is correct
13 Correct 9 ms 4952 KB Output is correct
14 Correct 9 ms 4952 KB Output is correct
15 Correct 9 ms 5464 KB Output is correct
16 Correct 9 ms 5468 KB Output is correct
17 Correct 11 ms 5468 KB Output is correct
18 Correct 11 ms 5468 KB Output is correct
19 Correct 16 ms 5724 KB Output is correct
20 Correct 11 ms 5724 KB Output is correct