#include "gap.h"
#include <stdio.h>
long long arr[100001];
long long findGap(int T, int N)
{
if(T == 1) {
long long min = 0;
long long max = 1e18;
int minIdx = 0;
int maxIdx = N-1;
int maxIter = (N+1)/2;
long long low;
long long high;
for(int i = 0; i < maxIter; i++) {
MinMax(min, max, &low, &high);
arr[minIdx++] = low;
arr[maxIdx--] = high;
min = low+1;
max = high-1;
}
long long result = 0;
for(int i =0; i < N-1; i++) {
if(arr[i+1] - arr[i] > result ) result = arr[i+1] - arr[i];
}
// for(int i =0 ; i< N ; i++) {
// printf("%lld ", arr[i]);
// }
// printf("\n");
return result;
} else {
long long min = 0;
long long max = 1e18;
long long low;
long long high;
MinMax(min, max, &low, &high);
min = low;
max = high;
long long distance = (high - low + N - 2) / (N - 1);
long long result = 0;
long long cmp = low;
long long left = min+1;
long long right = left + distance;
while(1) {
if(left >= max) break;
if(right >= max) right = max - 1;
MinMax(left, right, &low, &high);
// printf("left %d, right %d, low %lld, high %lld\n", left, right, low, high);
left = right + 1;
right = left + distance;
if(low == -1) continue;
if(result < low - cmp) result = low - cmp;
cmp = high;
}
if(max - cmp > result) result = max - cmp;
return result;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
6 |
Correct |
0 ms |
364 KB |
Output is correct |
7 |
Correct |
0 ms |
364 KB |
Output is correct |
8 |
Correct |
0 ms |
364 KB |
Output is correct |
9 |
Correct |
0 ms |
364 KB |
Output is correct |
10 |
Correct |
0 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
12 ms |
748 KB |
Output is correct |
17 |
Correct |
11 ms |
748 KB |
Output is correct |
18 |
Correct |
11 ms |
748 KB |
Output is correct |
19 |
Correct |
11 ms |
748 KB |
Output is correct |
20 |
Correct |
8 ms |
748 KB |
Output is correct |
21 |
Correct |
42 ms |
1900 KB |
Output is correct |
22 |
Correct |
45 ms |
2028 KB |
Output is correct |
23 |
Correct |
44 ms |
1900 KB |
Output is correct |
24 |
Correct |
44 ms |
1900 KB |
Output is correct |
25 |
Correct |
38 ms |
1900 KB |
Output is correct |
26 |
Correct |
43 ms |
2036 KB |
Output is correct |
27 |
Correct |
43 ms |
1900 KB |
Output is correct |
28 |
Correct |
43 ms |
1908 KB |
Output is correct |
29 |
Correct |
45 ms |
2064 KB |
Output is correct |
30 |
Correct |
34 ms |
1900 KB |
Output is correct |
31 |
Correct |
1 ms |
364 KB |
Output is correct |
32 |
Correct |
0 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
0 ms |
364 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
6 |
Correct |
0 ms |
364 KB |
Output is correct |
7 |
Correct |
0 ms |
364 KB |
Output is correct |
8 |
Correct |
0 ms |
364 KB |
Output is correct |
9 |
Correct |
0 ms |
364 KB |
Output is correct |
10 |
Correct |
0 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
14 ms |
492 KB |
Output is correct |
17 |
Correct |
14 ms |
492 KB |
Output is correct |
18 |
Correct |
16 ms |
492 KB |
Output is correct |
19 |
Correct |
14 ms |
492 KB |
Output is correct |
20 |
Correct |
7 ms |
492 KB |
Output is correct |
21 |
Correct |
67 ms |
1096 KB |
Output is correct |
22 |
Correct |
64 ms |
1260 KB |
Output is correct |
23 |
Correct |
59 ms |
1268 KB |
Output is correct |
24 |
Correct |
61 ms |
1132 KB |
Output is correct |
25 |
Correct |
54 ms |
1132 KB |
Output is correct |
26 |
Correct |
60 ms |
1116 KB |
Output is correct |
27 |
Correct |
59 ms |
1200 KB |
Output is correct |
28 |
Correct |
59 ms |
1248 KB |
Output is correct |
29 |
Correct |
60 ms |
1260 KB |
Output is correct |
30 |
Correct |
32 ms |
1132 KB |
Output is correct |
31 |
Correct |
0 ms |
364 KB |
Output is correct |
32 |
Correct |
0 ms |
364 KB |
Output is correct |