Submission #886908

# Submission time Handle Problem Language Result Execution time Memory
886908 2023-12-13T07:07:04 Z Zero_OP Rice Hub (IOI11_ricehub) C++14
17 / 100
58 ms 3712 KB
#include<bits/stdc++.h>

using namespace std;

#define range(v) begin(v), end(v)
#define compact(v) v.erase(unique(range(v)), end(v))

template<class T> bool minimize(T& a, T b){
  if(a > b) return a = b, true;
  return false;
}

template<class T> bool maximize(T& a, T b){
  if(a < b) return a = b, true;
  return false;
}

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const int N = 1e5 + 5;

int n, lim, x[N]; ll c, s[N];

ll f(int l, int r){
  if(l == r) return 0;
  ll avg = (s[r] - s[l - 1]) / (r - l + 1);
  int pos = upper_bound(x + l, x + r + 1, avg) - x - 1;

  int halfLeft = pos - l + 1;
  int halfRight = r - l + 1 - halfLeft;
  return (1LL * halfLeft * avg - (s[pos] - s[l - 1])) + ((s[r] - s[pos]) - 1LL * halfRight * avg);
}

int besthub(int R, int L, int X[0], ll B){
    n = R, lim = L; c = B;
    for(int i = 0; i < n; ++i){
      x[i + 1] = X[i];
      s[i + 1] = s[i] + X[i];
    }

    int ans = 0;
    for(int i = 1; i <= n; ++i){
      int l = 1, r = i, j = -1;
      while(l <= r){
        int mid = l + r >> 1;
        if(f(mid, i) <= c) j = mid, r = mid - 1;
        else l = mid + 1;
      }
      maximize(ans, i - j + 1);
    }
    return ans;
}

Compilation message

ricehub.cpp: In function 'int besthub(int, int, int*, ll)':
ricehub.cpp:47:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   47 |         int mid = l + r >> 1;
      |                   ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2496 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 1 ms 2492 KB Output is correct
22 Correct 1 ms 2492 KB Output is correct
23 Correct 1 ms 2396 KB Output is correct
24 Correct 1 ms 2396 KB Output is correct
25 Correct 1 ms 2396 KB Output is correct
26 Correct 1 ms 2396 KB Output is correct
27 Incorrect 1 ms 2396 KB Output isn't correct
28 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2512 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2392 KB Output is correct
17 Correct 1 ms 2392 KB Output is correct
18 Correct 1 ms 2392 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 3 ms 2396 KB Output is correct
22 Correct 3 ms 2396 KB Output is correct
23 Correct 2 ms 2396 KB Output is correct
24 Correct 2 ms 2396 KB Output is correct
25 Correct 3 ms 2396 KB Output is correct
26 Correct 2 ms 2396 KB Output is correct
27 Incorrect 2 ms 2536 KB Output isn't correct
28 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 2652 KB Output is correct
2 Correct 7 ms 2652 KB Output is correct
3 Correct 45 ms 3632 KB Output is correct
4 Correct 45 ms 3712 KB Output is correct
5 Correct 32 ms 2860 KB Output is correct
6 Correct 30 ms 2908 KB Output is correct
7 Correct 54 ms 3420 KB Output is correct
8 Correct 54 ms 3416 KB Output is correct
9 Correct 29 ms 2904 KB Output is correct
10 Correct 29 ms 2964 KB Output is correct
11 Correct 57 ms 3672 KB Output is correct
12 Correct 58 ms 3672 KB Output is correct
13 Incorrect 28 ms 2868 KB Output isn't correct
14 Halted 0 ms 0 KB -