답안 #717905

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
717905 2023-04-02T20:14:19 Z thimote75 쌀 창고 (IOI11_ricehub) C++14
100 / 100
107 ms 1128 KB
#include "ricehub.h"

#include <bits/stdc++.h>
#define num long long
#define inf 1e18

using namespace std;

vector<int> X;

int _besthub (int R, int L, num B) {
  int mxCount = 0;

  int left  = 0;
  int right = 0;
  num cost  = 0;
  
  for (int idx = 0; idx < R; idx ++) {
      //printf("a%d: %d %d [%lld]\n", idx, left, right, cost);
    while (cost > B) {
      if (left == right) {
        left = idx;
        right = idx;
        cost = 0;
        break;
      }

      num dlc = X[left ] - X[idx];
      num drc = X[right] - X[idx];

      cost -= max(dlc, drc);
      if (dlc >= drc) left ++;
      else right --;
    }
      //printf("b%d: %d %d [%lld]\n", idx, left, right, cost);

    while (right != R - 1) {
      //printf("bs%lld %d %d", cost, X[right + 1] - X[idx], X[right + 1] - X[idx] - (X[idx] - X[left]));
      if (X[right + 1] - X[idx] + cost <= B) {
        //printf("br\n");
        cost += X[right + 1] - X[idx];
        right ++;
      } else if (X[right + 1] - X[idx] < X[idx] - X[left]) {
        //printf("bl\n");
        cost += X[right + 1] - X[idx] - (X[idx] - X[left]);
        right ++;
        left ++;
      } else break ;
      //printf("be%lld %d %d\n", cost, X[right + 1] - X[idx], X[right + 1] - X[idx] - (X[idx] - X[left]));
    }
      //printf("\nc%d: %d %d [%lld]\n", idx, left, right, cost);

    if (idx + 1 != R) {
      num delta = X[idx + 1] - X[idx];

      cost += delta * (idx - left  + 1);
      cost -= delta * (right - idx);
    }
      //printf("d%d: %d %d [%lld]\n", idx, left, right, cost);
    mxCount = max(mxCount, right - left + 1);
  }

  return mxCount;
}

int besthubnaive(int R, int L, int X[], num B)
{
    int mxCount = 0;
 
    for (int idx = 0; idx < R; idx ++) {
      int left  = idx - 1;
      int right = idx + 1;
 
      num cost  = 0;
      int count = 1;
      while (true) {
        int dcl = left == -1 ? inf : abs(X[left]  - X[idx]);
        int dcr = right == R ? inf : abs(X[right] - X[idx]);
 
        if (min(dcl, dcr) + cost > B) break ;
        cost  += min(dcl, dcr);
        count ++;
        
        if (dcl <= dcr) left --;
        else right ++;
      }

      mxCount = max(count, mxCount);
    }
 
    return mxCount;
}
int besthub(int R, int L, int _X[], num B)
{
  X.resize(R);
  for (int i = 0; i < R; i ++)
    X[i] = _X[i];
  
  if (R <= 5000) return besthubnaive(R, L, _X, B);
  int res = _besthub(R, L, B);
  return res;

  /*if (res != besthubnaive(R, L, _X, B)) {
    printf("%d %d %lld\n", R, L, B);
    for (int u : X)
      printf("%d\n", u);
    printf("%d\n", besthubnaive(R, L, _X, B));
    exit(1);
  }

  exit(0);*/
}
# 결과 실행 시간 메모리 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 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 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 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 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 0 ms 212 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 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 256 KB Output is correct
20 Correct 1 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 1 ms 308 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 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 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 4 ms 212 KB Output is correct
4 Correct 4 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 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 1 ms 212 KB Output is correct
13 Correct 4 ms 212 KB Output is correct
14 Correct 5 ms 320 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 4 ms 212 KB Output is correct
18 Correct 4 ms 212 KB Output is correct
19 Correct 5 ms 316 KB Output is correct
20 Correct 5 ms 212 KB Output is correct
21 Correct 4 ms 340 KB Output is correct
22 Correct 4 ms 340 KB Output is correct
23 Correct 82 ms 340 KB Output is correct
24 Correct 79 ms 340 KB Output is correct
25 Correct 98 ms 340 KB Output is correct
26 Correct 107 ms 340 KB Output is correct
27 Correct 32 ms 344 KB Output is correct
28 Correct 31 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 12 ms 1108 KB Output is correct
4 Correct 12 ms 1044 KB Output is correct
5 Correct 6 ms 716 KB Output is correct
6 Correct 6 ms 596 KB Output is correct
7 Correct 10 ms 980 KB Output is correct
8 Correct 12 ms 1128 KB Output is correct
9 Correct 6 ms 716 KB Output is correct
10 Correct 6 ms 596 KB Output is correct
11 Correct 13 ms 980 KB Output is correct
12 Correct 13 ms 980 KB Output is correct
13 Correct 6 ms 596 KB Output is correct
14 Correct 8 ms 596 KB Output is correct
15 Correct 9 ms 888 KB Output is correct
16 Correct 10 ms 852 KB Output is correct
17 Correct 16 ms 916 KB Output is correct
18 Correct 11 ms 1020 KB Output is correct
19 Correct 11 ms 980 KB Output is correct
20 Correct 12 ms 988 KB Output is correct