답안 #776902

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
776902 2023-07-08T11:32:50 Z TimDee 쌀 창고 (IOI11_ricehub) C++17
100 / 100
31 ms 1492 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
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 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
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 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 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 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 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 0 ms 212 KB Output is correct
26 Correct 0 ms 212 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 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 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 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 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 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 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 2 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 2 ms 340 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 468 KB Output is correct
2 Correct 10 ms 468 KB Output is correct
3 Correct 13 ms 1492 KB Output is correct
4 Correct 14 ms 1472 KB Output is correct
5 Correct 27 ms 836 KB Output is correct
6 Correct 28 ms 852 KB Output is correct
7 Correct 13 ms 1492 KB Output is correct
8 Correct 13 ms 1404 KB Output is correct
9 Correct 30 ms 852 KB Output is correct
10 Correct 28 ms 852 KB Output is correct
11 Correct 15 ms 1492 KB Output is correct
12 Correct 14 ms 1460 KB Output is correct
13 Correct 29 ms 808 KB Output is correct
14 Correct 31 ms 852 KB Output is correct
15 Correct 10 ms 1108 KB Output is correct
16 Correct 10 ms 1108 KB Output is correct
17 Correct 12 ms 1364 KB Output is correct
18 Correct 12 ms 1268 KB Output is correct
19 Correct 13 ms 1364 KB Output is correct
20 Correct 13 ms 1364 KB Output is correct