답안 #787577

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
787577 2023-07-19T09:52:24 Z bane 쌀 창고 (IOI11_ricehub) C++17
100 / 100
57 ms 3128 KB
#include "ricehub.h"
#include <bits/stdc++.h>
using namespace std;

int besthub(int R, int L, int x[], long long B)
{

  vector<long long>X(R+1);
  X[0] = -(long long)1e18;
  for (int i = 1; i <= R; i++){
    X[i] = x[i - 1];
  }
  int l = 1, r = R;
  long long pf[R+1];
  pf[0] = 0;
  for (int i = 1; i<=R; i++){
    pf[i] = pf[i - 1] + X[i];
  }

  function<bool(int)>check = [&](int mid){
    int r = 0;
    int l = 1;
    while(r + 1 <= R){
      ++r;
      while(r - l + 1 > mid){
        ++l;
      }

      if (r - l + 1 == mid){
        int itt = (r + l) / 2;
        for (int it = itt - 20 ; it <= itt + 20; it++){
          if (it < l || it > r)continue;
          long long sum = 0;
          if (it != l){
            sum += (it - l) * X[it] - (pf[it-1] - pf[l-1]);
          }
          if (it != r){
            sum += -(r - it) * X[it] + (pf[r] - pf[it]);
          }
          if (sum <= B)return true;
        }
      }
    }

    return false;
  };
  while(l<=r){
    int mid = (l+r) / 2;
    if (check(mid)){
      l = mid + 1;
    }else{
      r = mid - 1;
    }
  }
  return l - 1;
}
# 결과 실행 시간 메모리 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
# 결과 실행 시간 메모리 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 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 232 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 1 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 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
# 결과 실행 시간 메모리 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 1 ms 212 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 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 264 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 232 KB Output is correct
12 Correct 1 ms 320 KB Output is correct
13 Correct 1 ms 304 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 212 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 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 ms 212 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 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 3 ms 340 KB Output is correct
28 Correct 3 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 596 KB Output is correct
2 Correct 22 ms 596 KB Output is correct
3 Correct 10 ms 2260 KB Output is correct
4 Correct 10 ms 2260 KB Output is correct
5 Correct 54 ms 1236 KB Output is correct
6 Correct 54 ms 1236 KB Output is correct
7 Correct 10 ms 2260 KB Output is correct
8 Correct 9 ms 2276 KB Output is correct
9 Correct 45 ms 1236 KB Output is correct
10 Correct 49 ms 1236 KB Output is correct
11 Correct 10 ms 2260 KB Output is correct
12 Correct 10 ms 2260 KB Output is correct
13 Correct 57 ms 1236 KB Output is correct
14 Correct 56 ms 1236 KB Output is correct
15 Correct 8 ms 1748 KB Output is correct
16 Correct 10 ms 1720 KB Output is correct
17 Correct 10 ms 2900 KB Output is correct
18 Correct 10 ms 2884 KB Output is correct
19 Correct 10 ms 3112 KB Output is correct
20 Correct 14 ms 3128 KB Output is correct