#include "gap.h"
#include <bits/stdc++.h>
using namespace std;
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) diff = max(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){
diff = max(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){
diff = max(diff, a - latest);
latest = b;
}
start+=l/n;
}
diff = max(diff, last - latest);
return diff;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 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 |
376 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 |
376 KB |
Output is correct |
11 |
Correct |
3 ms |
376 KB |
Output is correct |
12 |
Correct |
2 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 |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
15 ms |
760 KB |
Output is correct |
17 |
Correct |
15 ms |
764 KB |
Output is correct |
18 |
Correct |
16 ms |
760 KB |
Output is correct |
19 |
Correct |
15 ms |
760 KB |
Output is correct |
20 |
Correct |
11 ms |
760 KB |
Output is correct |
21 |
Correct |
57 ms |
1912 KB |
Output is correct |
22 |
Correct |
56 ms |
1916 KB |
Output is correct |
23 |
Correct |
57 ms |
2040 KB |
Output is correct |
24 |
Correct |
57 ms |
1944 KB |
Output is correct |
25 |
Correct |
48 ms |
1912 KB |
Output is correct |
26 |
Correct |
56 ms |
1912 KB |
Output is correct |
27 |
Correct |
57 ms |
1912 KB |
Output is correct |
28 |
Correct |
57 ms |
1912 KB |
Output is correct |
29 |
Correct |
56 ms |
1912 KB |
Output is correct |
30 |
Correct |
42 ms |
1916 KB |
Output is correct |
31 |
Correct |
2 ms |
376 KB |
Output is correct |
32 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
376 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 |
248 KB |
Output is correct |
9 |
Correct |
2 ms |
376 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 |
376 KB |
Output is correct |
16 |
Correct |
20 ms |
504 KB |
Output is correct |
17 |
Correct |
20 ms |
504 KB |
Output is correct |
18 |
Correct |
20 ms |
504 KB |
Output is correct |
19 |
Correct |
20 ms |
504 KB |
Output is correct |
20 |
Correct |
9 ms |
504 KB |
Output is correct |
21 |
Correct |
84 ms |
1144 KB |
Output is correct |
22 |
Correct |
76 ms |
1272 KB |
Output is correct |
23 |
Correct |
76 ms |
1044 KB |
Output is correct |
24 |
Correct |
76 ms |
1144 KB |
Output is correct |
25 |
Correct |
70 ms |
1144 KB |
Output is correct |
26 |
Correct |
77 ms |
1144 KB |
Output is correct |
27 |
Correct |
76 ms |
1144 KB |
Output is correct |
28 |
Correct |
76 ms |
1144 KB |
Output is correct |
29 |
Correct |
77 ms |
1144 KB |
Output is correct |
30 |
Correct |
39 ms |
1144 KB |
Output is correct |
31 |
Correct |
2 ms |
376 KB |
Output is correct |
32 |
Correct |
2 ms |
376 KB |
Output is correct |