Submission #1003242

# Submission time Handle Problem Language Result Execution time Memory
1003242 2024-06-20T08:10:17 Z HasanV11010238 Rice Hub (IOI11_ricehub) C++17
100 / 100
9 ms 3432 KB
/*#include "ricehub.h"
#include <bits/stdc++.h>
#define ll long long
using namespace std;
vector<ll> pr, x;
ll check(ll l, ll r, ll mid){
  int st = l, en = r, be = -1;
  while (st <= en){
    int mi = (st + en) / 2;
    if (x[mi] <= mid){
      st = mi + 1;
      be = mi;
    }
    else{
      en = mi - 1;
    }
  }
  ll su = mid * (be - l + 1) - (pr[be] - pr[l - 1]);
  su += (pr[r] - pr[be]) - mid * (r - be + 1);
  return su; 
}
int besthub(int R, int L, int X[], long long B)
{
  pr.assign(R + 1, 0), x.assign(R + 1, 0);
  for (int i = 1; i <= R; i++){
    x[i] = X[i - 1];
    pr[i] = pr[i - 1] + x[i];
  }
  ll l = 1, r = 1, ans = 0;
  while(r <= R){
    int mid = (x[l] + x[r]) / 2, mi1, mi2;
    auto it = upper_bound(x.begin(), x.end(), mid);
    if (it == x.end()){
      mi1 = mi2 = R;
    }
    else{
      mi2 = it - x.begin();
      mi1 = mi2 - 1;
    }
    ll va = min(check(l, r, mi1), check())
  }
  return ans;
}*/
#include "ricehub.h"
#include <bits/stdc++.h>
#define ll long long
using namespace std;
vector<ll> pr, x;
ll check(ll l, ll r, ll mid){
  ll su = x[mid] * (mid - l + 1) - (pr[mid] - pr[l - 1]);
  su += (pr[r] - pr[mid]) - x[mid] * (r - mid);
  return su; 
}
int besthub(int R, int L, int X[], long long B)
{
  pr.assign(R + 1, 0), x.assign(R + 1, 0);
  for (int i = 1; i <= R; i++){
    x[i] = X[i - 1];
    pr[i] = pr[i - 1] + x[i];
  }
  ll l = 1, r = 1, ans = 0;
  while(r <= R){
    if ((l + r) % 2 == 1){
      int mi1 = (l + r) / 2, mi2 = (l + r) / 2 + 1;
      ll va1 = check(l, r, mi1), va2 = check(l, r, mi2);
      if (l == 2 && r == 5){
        cout<<va1<<" "<<va2;
      }
      if (va1 > va2){
        swap(va1, va2);
      }
      if (va1 > B){
        l++;
      }
      else if (va1 <= B){
        r++;
        ans = max(ans, (r - l));
      }
    }
    else{
      int mi = (l + r) / 2;
      ll va = check(l, r, mi);
      if (va > B){
        l++;
      }
      else{
        r++;
        ans = max(ans, (r - l));
      }
    }
  }
  return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 440 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 444 KB Output is correct
25 Correct 0 ms 344 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 412 KB Output is correct
25 Correct 1 ms 452 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 2 ms 452 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1116 KB Output is correct
2 Correct 2 ms 860 KB Output is correct
3 Correct 9 ms 3420 KB Output is correct
4 Correct 9 ms 3432 KB Output is correct
5 Correct 4 ms 1628 KB Output is correct
6 Correct 4 ms 1756 KB Output is correct
7 Correct 8 ms 3176 KB Output is correct
8 Correct 8 ms 2992 KB Output is correct
9 Correct 4 ms 1628 KB Output is correct
10 Correct 4 ms 1624 KB Output is correct
11 Correct 9 ms 3376 KB Output is correct
12 Correct 9 ms 3416 KB Output is correct
13 Correct 4 ms 1628 KB Output is correct
14 Correct 4 ms 1804 KB Output is correct
15 Correct 7 ms 2652 KB Output is correct
16 Correct 7 ms 2652 KB Output is correct
17 Correct 8 ms 2908 KB Output is correct
18 Correct 8 ms 2908 KB Output is correct
19 Correct 8 ms 3132 KB Output is correct
20 Correct 9 ms 3160 KB Output is correct