답안 #685108

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
685108 2023-01-23T12:49:50 Z cadmiumsky 쌀 창고 (IOI11_ricehub) C++14
100 / 100
373 ms 2968 KB
#include <bits/stdc++.h>
#include "ricehub.h"

using namespace std;

using ll = long long;
//#define int ll 

#define sz(x) (x).size()
namespace {

  const int nmax = 1e5 + 5;
  const ll inf = 2e15 + 10;
  const double A = 0.38196601125, B = 1 - A;

  using pii = pair<int,int>;
  using tii = tuple<int,int,int>;
  using tiii = tuple<int,int,int,ll>;

  int n;
  int X[nmax];
  ll sum[nmax];

  #define sum (sum + 1)

}

ll get(int l, int mid, int r) {
  int ptrr = upper_bound(X, X + n, mid) - X;
  int ptrl = ptrr - 1;
  return (ll)(ptrl - l + 1) * mid - (sum[ptrl] - sum[l - 1]) + (sum[r] - sum[ptrr - 1]) - (ll)(r - ptrr + 1) * mid;
}

ll get(int l, int r) {
  if(l >= n || r >= n) return inf;
  int cl = X[l], cr = X[r];
  int ccl = B * (double)cl + A * (double)cr;
  int ccr = A * (double)cl + B * (double)cr;
  ll vl = get(l, ccl, r), vr = get(l, ccr, r);
  
  while(cr - cl > 4) {
    if(vl > vr) {
      cl = ccl;
      vl = vr;
      ccl = ccr;
      ccr = A * (double)cl + B * (double)cr;
      vr = get(l, ccr, r);
    }
    else {
      cr = ccr;
      vr = vl;
      ccr = ccl;
      ccl = B * (double)cl + A * (double)cr;
      vl = get(l, ccl, r);
    }
  } 
  
  
  ll mn = get(l, cl, r);
  for(int i = cl + 1; i <= cr; i++)
    mn = min(mn, get(l, i, r));
  return mn;
}

int besthub(int N, int vmx, int XX[], long long lim) {
  { // rename
    n = N;
    for(int j = 0; j < n; j++)  
      X[j] = XX[j];
  }
  { // spart
    for(int i = 0; i < n; i++) {
      sum[i] = sum[i - 1] + X[i];
    }
    sum[n] = sum[n - 1];
    sum[n + 1] = sum[n - 1];
  }
  
  int r = 0;
  int mx = 0;
  for(int l = 0; l < n; l++) {
    r = max(l, r);
    while(get(l, r) <= lim)
      r++;
    r--;
    mx = max(mx, r - l + 1);
  }
  return mx;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 312 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 308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 316 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 320 KB Output is correct
5 Correct 1 ms 308 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 1 ms 212 KB Output is correct
10 Correct 0 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 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 316 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 0 ms 312 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 308 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 312 KB Output is correct
24 Correct 1 ms 312 KB Output is correct
25 Correct 1 ms 308 KB Output is correct
26 Correct 2 ms 212 KB Output is correct
27 Correct 1 ms 212 KB Output is correct
28 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 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 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 2 ms 312 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 2 ms 340 KB Output is correct
20 Correct 2 ms 340 KB Output is correct
21 Correct 4 ms 340 KB Output is correct
22 Correct 6 ms 340 KB Output is correct
23 Correct 9 ms 340 KB Output is correct
24 Correct 9 ms 340 KB Output is correct
25 Correct 15 ms 340 KB Output is correct
26 Correct 12 ms 444 KB Output is correct
27 Correct 12 ms 436 KB Output is correct
28 Correct 15 ms 436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 724 KB Output is correct
2 Correct 35 ms 648 KB Output is correct
3 Correct 362 ms 2920 KB Output is correct
4 Correct 373 ms 2968 KB Output is correct
5 Correct 46 ms 1424 KB Output is correct
6 Correct 59 ms 1420 KB Output is correct
7 Correct 176 ms 2620 KB Output is correct
8 Correct 174 ms 2624 KB Output is correct
9 Correct 92 ms 1372 KB Output is correct
10 Correct 93 ms 1368 KB Output is correct
11 Correct 354 ms 2920 KB Output is correct
12 Correct 359 ms 2920 KB Output is correct
13 Correct 106 ms 1476 KB Output is correct
14 Correct 106 ms 1472 KB Output is correct
15 Correct 266 ms 2256 KB Output is correct
16 Correct 268 ms 2260 KB Output is correct
17 Correct 308 ms 2636 KB Output is correct
18 Correct 312 ms 2748 KB Output is correct
19 Correct 327 ms 2772 KB Output is correct
20 Correct 334 ms 2784 KB Output is correct