Submission #1104385

# Submission time Handle Problem Language Result Execution time Memory
1104385 2024-10-23T14:29:55 Z M_W_13 Rice Hub (IOI11_ricehub) C++17
100 / 100
16 ms 3464 KB
#include <bits/stdc++.h>
#include "ricehub.h"

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); i++)

int besthub(int R, int L, int X[], ll B)
{
    ll n = R;
    ll T[n];
    rep(i, n) {
        T[i] = X[i];
    }
    ll p = 0;
    ll k = n + 1;
    ll ans = k;
    while (p < k) {
        ll sr = (p + k)/2;
        int i1 = 0;
        int i2 = sr/2;
        ll ilelewa = i2 + 1;
        ll ileprawa = sr - ilelewa;
        ll S = 0;
        bool czy = false;
        rep(i, sr) {
            S += (abs(T[i] - T[i2]));
        }
        if (S <= B) {
            czy = true;
        }
        i1++;
        while (i1 + sr - 1 < n) {
            S -= abs(T[i1 - 1] - T[i2]);
            S += abs(T[i1 + sr - 1] - T[i2]);
            ilelewa--;
            ileprawa++;
            ll poz = T[i2];
            i2++;
            S += (ilelewa * (T[i2] - poz));
            S -= (ileprawa * (T[i2] - poz));
            ilelewa++;
            ileprawa--;
            if (S <= B) {
                czy = true;
            }
            i1++;
        }
        if (czy) {
            ans = sr;
            p = sr + 1;
        }
        else {
            k = sr;
        }
    }   
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 504 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Correct 1 ms 508 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 504 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 352 KB Output is correct
19 Correct 1 ms 504 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 432 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 2 ms 336 KB Output is correct
23 Correct 2 ms 460 KB Output is correct
24 Correct 2 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 2 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 592 KB Output is correct
2 Correct 3 ms 592 KB Output is correct
3 Correct 12 ms 3448 KB Output is correct
4 Correct 11 ms 3408 KB Output is correct
5 Correct 6 ms 2896 KB Output is correct
6 Correct 9 ms 2896 KB Output is correct
7 Correct 9 ms 3408 KB Output is correct
8 Correct 13 ms 3464 KB Output is correct
9 Correct 6 ms 2896 KB Output is correct
10 Correct 5 ms 2896 KB Output is correct
11 Correct 10 ms 3408 KB Output is correct
12 Correct 10 ms 3408 KB Output is correct
13 Correct 6 ms 2896 KB Output is correct
14 Correct 6 ms 2896 KB Output is correct
15 Correct 8 ms 3152 KB Output is correct
16 Correct 8 ms 3188 KB Output is correct
17 Correct 9 ms 3152 KB Output is correct
18 Correct 16 ms 3152 KB Output is correct
19 Correct 10 ms 3408 KB Output is correct
20 Correct 10 ms 3408 KB Output is correct