Submission #233361

# Submission time Handle Problem Language Result Execution time Memory
233361 2020-05-20T10:26:27 Z Coroian_David Rice Hub (IOI11_ricehub) C++11
100 / 100
24 ms 3448 KB
#include <bits/stdc++.h>

#include "ricehub.h"

#define MAX_R 100000
#define MAX_N 100000

using namespace std;

typedef long long lint;

int n;

lint v[MAX_N + 1];
lint sum[MAX_N + 1];
lint bani;

bool pos(int len)
{
   // cout << " INTRA LEN " << len << "\n";

  // cout << sum[n] << "\n";

    for(int i = len; i <= n; i ++)
    {
        int st = i - len + 1;

        int med = ((len + 1) >> 1);
        int p = st - 1 + med;

       // cout << " SPRE ST AVEM " << med * v[p] << " - " << (sum[p] - sum[st - 1]) << "\n";
       // cout << " SPRE DR AVEM " << (sum[i] - sum[p]) << " - " <<  (i - med) * v[p] << "\n";

        lint cost = med * v[p] - (sum[p] - sum[st - 1]) +
                    (sum[i] - sum[p]) - (i - p) * v[p];

       // if(len <= 4)
        //cout << " SUNTEM " << st << " " << p << " " << i << " len " << len << " COSt " << cost << "\n";

        if(cost <= bani)
            return 1;
    }

    return 0;
}

int cautBin()
{
    int i = 0;
    int pas = 1 << 16;
    while(pas != 0)
    {
        if(i + pas <= n && pos(i + pas) == 1)
            i += pas;

        pas >>= 1;
    }

    return i;
}

int besthub(int R, int L, int X[], long long B)
{
    bani = B;
    n = R;

    sum[1] = X[0];
    v[1] = X[0];
    for(int i = 2; i <= n; i ++)
    {
        v[i] = X[i - 1];
        sum[i] = sum[i - 1] + v[i];
    }

    int rez = cautBin();

    return rez;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 4 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 416 KB Output is correct
24 Correct 4 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 4 ms 384 KB Output is correct
28 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 4 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 512 KB Output is correct
23 Correct 5 ms 512 KB Output is correct
24 Correct 5 ms 512 KB Output is correct
25 Correct 5 ms 512 KB Output is correct
26 Correct 6 ms 512 KB Output is correct
27 Correct 5 ms 512 KB Output is correct
28 Correct 6 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 896 KB Output is correct
2 Correct 8 ms 896 KB Output is correct
3 Correct 22 ms 3328 KB Output is correct
4 Correct 22 ms 3328 KB Output is correct
5 Correct 13 ms 1664 KB Output is correct
6 Correct 14 ms 1664 KB Output is correct
7 Correct 20 ms 3072 KB Output is correct
8 Correct 20 ms 3072 KB Output is correct
9 Correct 12 ms 1536 KB Output is correct
10 Correct 12 ms 1536 KB Output is correct
11 Correct 24 ms 3448 KB Output is correct
12 Correct 24 ms 3328 KB Output is correct
13 Correct 13 ms 1664 KB Output is correct
14 Correct 14 ms 1664 KB Output is correct
15 Correct 19 ms 2560 KB Output is correct
16 Correct 19 ms 2560 KB Output is correct
17 Correct 21 ms 2944 KB Output is correct
18 Correct 22 ms 3072 KB Output is correct
19 Correct 22 ms 3192 KB Output is correct
20 Correct 23 ms 3192 KB Output is correct