Submission #168935

# Submission time Handle Problem Language Result Execution time Memory
168935 2019-12-17T08:51:26 Z AlexLuchianov Rice Hub (IOI11_ricehub) C++14
100 / 100
518 ms 3448 KB
#include "ricehub.h"
#include <iostream>

using ll = long long;
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))

int const nmax = 100000;
int n, lim;
ll v[1 + nmax], sum[1 + nmax];

///returns position of the last farm with coordinate lower (or equal) than target

int lowerthan(int target){
  int x = 0;
  for(int jump = (1 << 20); 0 < jump; jump /= 2)
    if(x + jump <= n && v[x + jump] <= target)
      x += jump;
  return x;
}

ll tryit(int pos, ll dist, ll budget){
  int pos2 = lowerthan(v[pos] + dist), pos3 = lowerthan(v[pos] - dist - 1) + 1;

  ll result = ((sum[pos2] - sum[pos - 1]) - (pos2 - pos + 1) * v[pos]);
  ll result2 = (pos - pos3 + 1) * v[pos] - (sum[pos] - sum[pos3 - 1]);

  return result + result2 <= budget;
}

ll solve(int pos, ll budget){
  int dist = 0;
  for(int jump = (1 << 30); 0 < jump; jump /= 2){
    if(dist + jump <= lim && tryit(pos, dist + jump, budget))
      dist += jump;
  }
  dist++;


  int pos2 = lowerthan(v[pos] + dist), pos3 = lowerthan(v[pos] - dist - 1) + 1;

  ll result = ((sum[pos2] - sum[pos - 1]) - (pos2 - pos + 1) * v[pos]);
  ll result2 = (pos - pos3 + 1) * v[pos] - (sum[pos] - sum[pos3 - 1]);
  result = result + result2;


  if(result <= budget)
    return (pos2 - pos3 + 1);
  else
    return (pos2 - pos3 + 1) - (result - budget + dist - 1) / dist;
}

int besthub(int R, int L, int X[], long long B)
{
  lim = L;
  n = R;
  for(int i = 1;i <= n; i++)
    v[i] = X[i - 1];
  for(int i = 1;i <= n; i++)
    sum[i] = sum[i - 1] + v[i];

  int result = 0;
  for(int i = 1;i <= n; i++) {
    int result2 = solve(i, B);
    result = MAX(result, result2);
  }
  return result;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 328 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 372 KB Output is correct
25 Correct 2 ms 360 KB Output is correct
26 Correct 2 ms 376 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 380 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 3 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 3 ms 376 KB Output is correct
12 Correct 3 ms 376 KB Output is correct
13 Correct 3 ms 376 KB Output is correct
14 Correct 3 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 380 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 3 ms 376 KB Output is correct
19 Correct 3 ms 376 KB Output is correct
20 Correct 4 ms 376 KB Output is correct
21 Correct 8 ms 528 KB Output is correct
22 Correct 8 ms 504 KB Output is correct
23 Correct 5 ms 504 KB Output is correct
24 Correct 9 ms 404 KB Output is correct
25 Correct 10 ms 504 KB Output is correct
26 Correct 11 ms 504 KB Output is correct
27 Correct 12 ms 508 KB Output is correct
28 Correct 11 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 760 KB Output is correct
2 Correct 44 ms 852 KB Output is correct
3 Correct 225 ms 2316 KB Output is correct
4 Correct 515 ms 3448 KB Output is correct
5 Correct 126 ms 1656 KB Output is correct
6 Correct 127 ms 1740 KB Output is correct
7 Correct 131 ms 3064 KB Output is correct
8 Correct 357 ms 3192 KB Output is correct
9 Correct 116 ms 1656 KB Output is correct
10 Correct 115 ms 1656 KB Output is correct
11 Correct 230 ms 3320 KB Output is correct
12 Correct 518 ms 3448 KB Output is correct
13 Correct 147 ms 1784 KB Output is correct
14 Correct 142 ms 1656 KB Output is correct
15 Correct 169 ms 2708 KB Output is correct
16 Correct 420 ms 2552 KB Output is correct
17 Correct 228 ms 3064 KB Output is correct
18 Correct 462 ms 3192 KB Output is correct
19 Correct 221 ms 3192 KB Output is correct
20 Correct 489 ms 3324 KB Output is correct