#include "gap.h"
typedef long long ll;
ll findGap(int T, int n){
if(T == 1){
ll arr[100100];
ll i=0, j=n-1;
ll minval=0, maxval=1000000000000000000;
while(i<j){
MinMax(minval, maxval, &minval, &maxval);
arr[i++]=minval++;
arr[j--]=maxval--;
}
if(i == j){
MinMax(minval, maxval, &minval, &maxval);
arr[i]=minval;
}
ll diff=0;
for(int j=1; j<n; ++j){
if(arr[j]-arr[j-1] > diff) diff = arr[j]-arr[j-1];
}
return diff;
}
else {
ll first=0, last=1000000000000000000;
MinMax(first, last, &first, &last);
ll l = last - first - 1;
ll mod = l % n;
ll diff = l/n;
ll start = first + 1;
ll a, b;
ll latest = first;
for(int i=0; i<mod; ++i){
MinMax(start, start + l/n + (mod != 0) - 1, &a, &b);
if(a >= 0){
if(a - latest >= diff) diff = a - latest;
latest = b;
}
start = start + l/n + (mod != 0);
}
for(int i=mod; i<n; ++i){
MinMax(start, start + l/n - 1, &a, &b);
if(a >= 0){
if(a - latest >= diff) diff = a - latest;
latest = b;
}
start+=l/n;
}
if(last - latest >= diff) diff = last - latest;
return diff;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
256 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
3 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
15 ms |
632 KB |
Output is correct |
17 |
Correct |
15 ms |
760 KB |
Output is correct |
18 |
Correct |
15 ms |
632 KB |
Output is correct |
19 |
Correct |
15 ms |
632 KB |
Output is correct |
20 |
Correct |
11 ms |
760 KB |
Output is correct |
21 |
Correct |
55 ms |
1912 KB |
Output is correct |
22 |
Correct |
55 ms |
1912 KB |
Output is correct |
23 |
Correct |
55 ms |
1804 KB |
Output is correct |
24 |
Correct |
57 ms |
1912 KB |
Output is correct |
25 |
Correct |
47 ms |
1884 KB |
Output is correct |
26 |
Correct |
56 ms |
1912 KB |
Output is correct |
27 |
Correct |
56 ms |
2040 KB |
Output is correct |
28 |
Correct |
56 ms |
1912 KB |
Output is correct |
29 |
Correct |
55 ms |
1892 KB |
Output is correct |
30 |
Correct |
41 ms |
1912 KB |
Output is correct |
31 |
Correct |
2 ms |
376 KB |
Output is correct |
32 |
Correct |
2 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
256 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
3 ms |
376 KB |
Output is correct |
12 |
Correct |
3 ms |
376 KB |
Output is correct |
13 |
Correct |
3 ms |
376 KB |
Output is correct |
14 |
Correct |
3 ms |
376 KB |
Output is correct |
15 |
Correct |
3 ms |
256 KB |
Output is correct |
16 |
Correct |
19 ms |
504 KB |
Output is correct |
17 |
Correct |
19 ms |
508 KB |
Output is correct |
18 |
Correct |
19 ms |
504 KB |
Output is correct |
19 |
Correct |
19 ms |
504 KB |
Output is correct |
20 |
Correct |
9 ms |
504 KB |
Output is correct |
21 |
Correct |
75 ms |
1144 KB |
Output is correct |
22 |
Correct |
74 ms |
1144 KB |
Output is correct |
23 |
Correct |
74 ms |
1144 KB |
Output is correct |
24 |
Correct |
74 ms |
1144 KB |
Output is correct |
25 |
Correct |
68 ms |
1272 KB |
Output is correct |
26 |
Correct |
75 ms |
1144 KB |
Output is correct |
27 |
Correct |
74 ms |
1144 KB |
Output is correct |
28 |
Correct |
75 ms |
1144 KB |
Output is correct |
29 |
Correct |
75 ms |
1144 KB |
Output is correct |
30 |
Correct |
38 ms |
1144 KB |
Output is correct |
31 |
Correct |
2 ms |
376 KB |
Output is correct |
32 |
Correct |
2 ms |
256 KB |
Output is correct |