Submission #680088

# Submission time Handle Problem Language Result Execution time Memory
680088 2023-01-09T21:54:06 Z raysh07 Rice Hub (IOI11_ricehub) C++17
68 / 100
55 ms 4588 KB
#include "ricehub.h"
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 1e5 + 69;
ll seg[4*maxn];
ll a[maxn];
int n;

void Build(int l, int r, int pos){
  if (l==r){
    seg[pos] = a[l];
    return;
  }
  int mid = (l+r)/2;
  Build(l, mid, pos*2);
  Build(mid + 1, r, pos*2 + 1);
  seg[pos] = seg[pos * 2] + seg[pos * 2 + 1];
}

int Query(int l, int r, int pos, int ql, int qr){
  if (l>r) return 0;
  if (l>=ql && r<=qr)
    return seg[pos];

  else if (l>qr || ql>r) return 0;

  int mid = (l+r)/2;
  return Query(l, mid, pos*2, ql, qr) + Query(mid + 1, r, pos*2 + 1, ql, qr);
}

bool check(int l, int r, ll B){
  int mid = (l+r)/2;
  int pos = a[mid];
  ll val = (mid - l + 1) * pos - Query(1, n, 1, l, mid);
  val += Query(1, n, 1, mid, r) - (r - mid + 1) * pos;

  return val <= B;
}

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

    Build(1, n, 1);

    int ans = 0;
    int r = 0;

    for (int l=1; l<=n; l++){
      while (r!=n && check(l, r+1, B))
      r++;
      ans = max(ans, r-l+1);
    }
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 304 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 300 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 308 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 308 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 308 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 308 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 308 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 304 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 312 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 4 ms 444 KB Output is correct
22 Correct 4 ms 448 KB Output is correct
23 Correct 2 ms 468 KB Output is correct
24 Correct 2 ms 468 KB Output is correct
25 Correct 2 ms 468 KB Output is correct
26 Correct 2 ms 468 KB Output is correct
27 Correct 3 ms 468 KB Output is correct
28 Correct 3 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 1068 KB Output is correct
2 Correct 14 ms 1192 KB Output is correct
3 Correct 55 ms 4588 KB Output is correct
4 Incorrect 40 ms 4540 KB Output isn't correct
5 Halted 0 ms 0 KB -