Submission #776898

# Submission time Handle Problem Language Result Execution time Memory
776898 2023-07-08T11:30:22 Z I_Love_EliskaM_ Rice Hub (IOI11_ricehub) C++14
100 / 100
31 ms 2560 KB
#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;
#define forn(i,n) for(int i=0;i<n;++i)
#define pi pair<int,int>
#define f first
#define s second
#define pb push_back
#define all(x) x.begin(), x.end()
using ll = long long;
#define int ll

struct BIT {
  vector<int> t; int n;
  BIT(int n) {
    this->n=n;
    t.assign(n,0);
  }
  void add(int i, int x) {
    for(;i<n;i=i|(i+1)) t[i]+=x;
  }
  int sum(int r) {
    int q=0;
    for(;r>=0;r=(r&(r+1))-1) q+=t[r];
    return q;
  }
  int sum(int l, int r) {
    return sum(r)-sum(l-1);
  }
};
#undef int

int besthub(int n, int L, int x[], ll b) {
  #define int ll
  BIT ft(n);
  forn(i,n) ft.add(i,x[i]);
  int l=1, r=n;
  while (l<r) {
    int m=(l+r+1)>>1;
    ll mn=1e18;
    for (int i=0; i+m<=n; ++i) {
      int t = (i+m/2);
      ll z = 1ll*x[t]*(t-i+1)-ft.sum(i,t) + ft.sum(t,i+m-1)-1ll*(i+m-t)*x[t];
      mn=min(mn,z);
    }
    if (mn>b) r=m-1;
    else l=m;
  }
  return r;
  #undef int
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 308 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 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 312 KB Output is correct
7 Correct 1 ms 308 KB Output is correct
8 Correct 1 ms 308 KB Output is correct
9 Correct 0 ms 308 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 312 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 320 KB Output is correct
17 Correct 1 ms 312 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 312 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 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 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 312 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 256 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 316 KB Output is correct
20 Correct 1 ms 312 KB Output is correct
21 Correct 3 ms 340 KB Output is correct
22 Correct 3 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 352 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 596 KB Output is correct
2 Correct 12 ms 632 KB Output is correct
3 Correct 14 ms 2504 KB Output is correct
4 Correct 16 ms 2468 KB Output is correct
5 Correct 27 ms 1224 KB Output is correct
6 Correct 28 ms 1236 KB Output is correct
7 Correct 14 ms 2212 KB Output is correct
8 Correct 13 ms 2140 KB Output is correct
9 Correct 30 ms 1108 KB Output is correct
10 Correct 28 ms 1108 KB Output is correct
11 Correct 14 ms 2560 KB Output is correct
12 Correct 14 ms 2516 KB Output is correct
13 Correct 29 ms 1224 KB Output is correct
14 Correct 31 ms 1236 KB Output is correct
15 Correct 11 ms 1876 KB Output is correct
16 Correct 11 ms 1868 KB Output is correct
17 Correct 13 ms 2192 KB Output is correct
18 Correct 13 ms 2260 KB Output is correct
19 Correct 13 ms 2360 KB Output is correct
20 Correct 14 ms 2384 KB Output is correct