Submission #494006

# Submission time Handle Problem Language Result Execution time Memory
494006 2021-12-13T17:50:53 Z Ozy Rice Hub (IOI11_ricehub) C++17
100 / 100
13 ms 2508 KB
#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define rep(i,a,b) for (int i = (a); i <= (b); i++)
#define repa(i,a,b) for (int i = (a); i >= (b); i--)
#define debug(a) cout << #a << " = " << a << endl
#define debugsl(a) cout << #a << " = " << a << ", "

#define MAX 100000

lli n,l,b,ini,fin,mitad,res,centro;
lli arr[MAX+2];

bool sepuede(lli num) {
    lli dif,sum = 0;

    centro = (num+1)/2;
    rep(i,1,num) sum += abs(arr[centro]-arr[i]);
    if (sum <= b) return true;

    rep(i,1,(n-num)) {

        dif = arr[centro+1] - arr[centro];

        sum -= arr[centro] - arr[i];
        if (!(num&1)) sum -= dif;
        centro++;

        sum += arr[i+num] - arr[centro];
        if (sum <= b) return true;
    }

    return false;
}

int besthub(int R, int L, int X[], long long B)
{

    n = R;
    l = L;
    rep(i,0,n-1) arr[i+1] = X[i];
    b = B;

    ini = 1;
    fin = n;
    while (ini <= fin) {
        mitad = (ini+fin)/2;

        if (sepuede(mitad)) {
            ini = mitad+1;
            res = mitad;
        }
        else fin = mitad-1;
    }

    return res;
}
# 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 1 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 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 304 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 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 300 KB Output is correct
12 Correct 1 ms 300 KB Output is correct
13 Correct 1 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 1 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 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 0 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 0 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 304 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 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 292 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 1 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 1 ms 204 KB Output is correct
17 Correct 1 ms 308 KB Output is correct
18 Correct 1 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 316 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 460 KB Output is correct
2 Correct 2 ms 460 KB Output is correct
3 Correct 12 ms 2508 KB Output is correct
4 Correct 13 ms 2500 KB Output is correct
5 Correct 6 ms 1200 KB Output is correct
6 Correct 6 ms 1228 KB Output is correct
7 Correct 12 ms 2124 KB Output is correct
8 Correct 12 ms 2124 KB Output is correct
9 Correct 9 ms 1124 KB Output is correct
10 Correct 6 ms 1076 KB Output is correct
11 Correct 12 ms 2508 KB Output is correct
12 Correct 12 ms 2488 KB Output is correct
13 Correct 6 ms 1228 KB Output is correct
14 Correct 6 ms 1228 KB Output is correct
15 Correct 9 ms 1868 KB Output is correct
16 Correct 11 ms 1868 KB Output is correct
17 Correct 11 ms 2252 KB Output is correct
18 Correct 11 ms 2256 KB Output is correct
19 Correct 13 ms 2420 KB Output is correct
20 Correct 13 ms 2312 KB Output is correct