#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int MAXN = 1e5+10;
ll pref1[MAXN],pref2[MAXN],arr[MAXN];
int X[5] = {1,2,10,12,14};
int besthub(int R,int L,int X[],ll B){
for(int i = 0;i<R;++i){
arr[i+1] = X[i];
}
for(int i = 1;i<=R;++i){
pref1[i] = pref1[i-1]+arr[i]; //-> pref[1] = distance from 1 to X[1]
//cout << pref1[i] << "\n";
}
pref1[R+1] = L-pref1[R];
/*for(int i = 1;i<=R+1;++i){
pref2[i] = pref2[i-1]+pref1[i];
cout << pref2[i] << "\n";
}*/
int lo = -1, hi = R;
while(lo < hi){
int mid = lo+(hi-lo+1)/2;
bool good = false;
if(mid % 2 == 0){
int i = 1; //number of the first field, one-indexed and all
while(i+mid-1 <= R){
int m = (i+(mid/2));
ll cur = pref1[i+mid-1]-pref1[m-1]-(pref1[m-1]-pref1[i-1]);
//ll cur = pref1[i+mid]-pref1[m]-(pref1[m]-pref1[i]);
//cout << i << " " << cur << " " << mid << "\n";
if(cur <= B){
good = true;
break;
}
++i;
}
}
else{
int i = 1; //number of the first field, one-indexed and all
while(i+mid-1 <= R){
int m = (i+(mid/2));
ll cur = pref1[i+mid-1]-pref1[m]-(pref1[m-1]-pref1[i-1]);
//ll cur = pref1[i+mid]-pref1[m+1]-(pref1[m]-pref1[i]);
//cout << i << " " << cur << " " << mid << "\n";
if(cur <= B){
good = true;
break;
}
++i;
}
}
if(good){
lo = mid;
}
else{
hi = mid-1;
}
}
return lo;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
604 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
448 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
360 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
452 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
448 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
376 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
484 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
492 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
604 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
856 KB |
Output is correct |
2 |
Correct |
2 ms |
860 KB |
Output is correct |
3 |
Correct |
8 ms |
3416 KB |
Output is correct |
4 |
Correct |
8 ms |
3452 KB |
Output is correct |
5 |
Correct |
4 ms |
1600 KB |
Output is correct |
6 |
Correct |
4 ms |
1628 KB |
Output is correct |
7 |
Correct |
7 ms |
3020 KB |
Output is correct |
8 |
Correct |
7 ms |
3164 KB |
Output is correct |
9 |
Correct |
4 ms |
1628 KB |
Output is correct |
10 |
Correct |
3 ms |
1628 KB |
Output is correct |
11 |
Correct |
10 ms |
3528 KB |
Output is correct |
12 |
Correct |
8 ms |
3420 KB |
Output is correct |
13 |
Correct |
4 ms |
1628 KB |
Output is correct |
14 |
Correct |
4 ms |
1780 KB |
Output is correct |
15 |
Correct |
5 ms |
2496 KB |
Output is correct |
16 |
Correct |
6 ms |
2652 KB |
Output is correct |
17 |
Correct |
7 ms |
2908 KB |
Output is correct |
18 |
Correct |
8 ms |
3020 KB |
Output is correct |
19 |
Correct |
7 ms |
3264 KB |
Output is correct |
20 |
Correct |
7 ms |
3164 KB |
Output is correct |