이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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);*/
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |