Submission #261544

# Submission time Handle Problem Language Result Execution time Memory
261544 2020-08-11T20:51:00 Z sandoval Rice Hub (IOI11_ricehub) C++11
17 / 100
1000 ms 1536 KB
#include "ricehub.h"
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int besthub(int R, int L, int X[], long long B) {
  const int n = R;
  vector<ll> pre(X, X+n);

  for (int i = 1; i < n; ++i) pre[i] += pre[i-1];

  auto sum = [](const vector<ll>& ps, int l, int r)->long long{
    if (l > r) return 0LL;
    ll ans = ps[r];
    if (l > 0) ans -= ps[l-1];
    return ans;
  };

  auto get = [&sum](int l, int r, const vector<ll>& ps, int a[], ll p)->long long{
    int idx = upper_bound(a+l, a+r+1, p) - a;
    int g = max(0, 1+r-idx);
    int le = max(0, idx-l);
    ll ans = 0;
    for (int i = l; i <= r; ++i) ans += abs(p-a[i]);
    assert(ans == p*1LL*le-sum(ps,l,idx-1)+sum(ps,idx,r)-1LL*g*p);
    return p*1LL*le-sum(ps,l,idx-1)+sum(ps,idx,r)-1LL*g*p;
  };

  auto cost = [&get, &sum](int l, int r, const vector<ll>& ps, int x[])->long long{
    long long av = sum(ps, l, r)/ll(1+r-l);
    int idx = upper_bound(x+l, x+r+1, av) - x;
    int op1 = idx-1;
    int op2 = idx;
    ll a = numeric_limits<ll>::max();
    ll b = numeric_limits<ll>::max();

    if (op1 >= l && op1 <= r) {
      a = get(l, r, ps, x, x[op1]);
    }

    if (op2 >= l && op2 <= r) {
      b = get(l, r, ps, x, x[op2]);
    }

    return min(a,b);
  };

  int ans = 1;
  for (int i = 0; i < n; ++i) {
    int low = i, high = n-1, best = -1;
    while (low <= high) {
      int mid = (low+high) >> 1;
      if (cost(i,mid,pre,X) <= B) {
        low = 1+mid;
        best = mid;
      } else {
        high = mid-1;
      }
    }
    assert(best >= i && best < n);
    ans = max(ans, 1+best-i);
  }
  return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 0 ms 256 KB Output is correct
12 Correct 1 ms 256 KB Output is correct
13 Correct 1 ms 256 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 1 ms 256 KB Output is correct
16 Correct 1 ms 256 KB Output is correct
17 Correct 1 ms 256 KB Output is correct
18 Correct 0 ms 256 KB Output is correct
19 Correct 1 ms 256 KB Output is correct
20 Correct 1 ms 256 KB Output is correct
21 Correct 1 ms 256 KB Output is correct
22 Correct 2 ms 256 KB Output is correct
23 Correct 3 ms 256 KB Output is correct
24 Correct 3 ms 256 KB Output is correct
25 Correct 4 ms 384 KB Output is correct
26 Correct 3 ms 384 KB Output is correct
27 Incorrect 2 ms 256 KB Output isn't correct
28 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 1 ms 256 KB Output is correct
3 Correct 9 ms 256 KB Output is correct
4 Correct 8 ms 384 KB Output is correct
5 Correct 1 ms 256 KB Output is correct
6 Correct 1 ms 256 KB Output is correct
7 Correct 5 ms 256 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 2 ms 256 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 3 ms 256 KB Output is correct
13 Correct 11 ms 384 KB Output is correct
14 Correct 10 ms 308 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 3 ms 256 KB Output is correct
17 Correct 7 ms 256 KB Output is correct
18 Correct 7 ms 256 KB Output is correct
19 Correct 10 ms 384 KB Output is correct
20 Correct 10 ms 384 KB Output is correct
21 Correct 48 ms 384 KB Output is correct
22 Correct 48 ms 384 KB Output is correct
23 Correct 300 ms 384 KB Output is correct
24 Correct 285 ms 504 KB Output is correct
25 Correct 302 ms 384 KB Output is correct
26 Correct 287 ms 384 KB Output is correct
27 Incorrect 217 ms 384 KB Output isn't correct
28 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 445 ms 512 KB Output is correct
2 Correct 451 ms 512 KB Output is correct
3 Execution timed out 1092 ms 1536 KB Time limit exceeded
4 Halted 0 ms 0 KB -