#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];
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 |
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 |
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 |
6 |
Correct |
1 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 |
284 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 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 |
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 |
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 |
1 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 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
28 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
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 |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
340 KB |
Output is correct |
2 |
Correct |
2 ms |
468 KB |
Output is correct |
3 |
Correct |
11 ms |
1108 KB |
Output is correct |
4 |
Correct |
13 ms |
2128 KB |
Output is correct |
5 |
Correct |
6 ms |
936 KB |
Output is correct |
6 |
Correct |
5 ms |
980 KB |
Output is correct |
7 |
Correct |
11 ms |
1764 KB |
Output is correct |
8 |
Correct |
12 ms |
1780 KB |
Output is correct |
9 |
Correct |
6 ms |
980 KB |
Output is correct |
10 |
Correct |
5 ms |
980 KB |
Output is correct |
11 |
Correct |
13 ms |
2076 KB |
Output is correct |
12 |
Correct |
14 ms |
2132 KB |
Output is correct |
13 |
Correct |
7 ms |
1096 KB |
Output is correct |
14 |
Correct |
7 ms |
984 KB |
Output is correct |
15 |
Correct |
10 ms |
1632 KB |
Output is correct |
16 |
Correct |
10 ms |
1580 KB |
Output is correct |
17 |
Correct |
11 ms |
1948 KB |
Output is correct |
18 |
Correct |
13 ms |
1936 KB |
Output is correct |
19 |
Correct |
12 ms |
1988 KB |
Output is correct |
20 |
Correct |
13 ms |
1964 KB |
Output is correct |