#include <bits/stdc++.h>
#include "gap.h"
using namespace std;
typedef long long ll;
//#define DEBUG
#ifdef DEBUG
int n = 2;
ll a[2] = {78103569500113815, 605712887753065418 };
void MinMax(ll x, ll y, ll *mn, ll *mx) {
for (int i = 0; i < n; ++i) if (a[i] >= x)
{ (*mn) = a[i]; break; }
for (int i = n - 1; i >= 0; --i) if (a[i] <= y)
{ (*mx) = a[i]; break; }
if ((*mx) < (*mn)) (*mx) = (*mn) = -1;
}
#endif
ll findGap(int _t, int _n) {
ll n = _n;
ll mn = 1, mx = (ll)1e18;
MinMax(mn, mx, &mn, &mx);
if (_t == 2) {
ll d = ceil((double)(mx - mn) / (double)(n - 1ll)), pre = mn, gap = 0;
for (ll i = mn; i < mx; i += d) {
MinMax(i, i + d - 1, &mn, &mx);
if (mn == -1) continue;
gap = max(gap, mn - pre);
pre = mx;
}
gap = max(gap, mx - pre);
return gap;
} else {
vector<ll> a;
a.resize(n);
a[0] = mn, a[n - 1] = mx;
int lo = 0, hi = n - 1;
while (hi - lo > 1) {
MinMax(a[lo] + 1ll, a[hi] - 1ll, &mn, &mx);
++lo, --hi;
a[lo] = mn, a[hi] = mx;
}
ll gap = 0;
for (int i = 0; i < n - 1; ++i) gap = max(gap, a[i + 1] - a[i]);
return gap;
}
return 0ll;
}
#ifdef DEBUG
int main() {
printf("%d", findGap(1, 5));
return 0;
}
#endif
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
248 KB |
Output is correct |
2 |
Correct |
2 ms |
352 KB |
Output is correct |
3 |
Correct |
1 ms |
404 KB |
Output is correct |
4 |
Correct |
1 ms |
404 KB |
Output is correct |
5 |
Correct |
2 ms |
404 KB |
Output is correct |
6 |
Correct |
1 ms |
460 KB |
Output is correct |
7 |
Correct |
2 ms |
532 KB |
Output is correct |
8 |
Correct |
1 ms |
548 KB |
Output is correct |
9 |
Correct |
2 ms |
548 KB |
Output is correct |
10 |
Correct |
1 ms |
548 KB |
Output is correct |
11 |
Correct |
2 ms |
548 KB |
Output is correct |
12 |
Correct |
2 ms |
624 KB |
Output is correct |
13 |
Correct |
2 ms |
624 KB |
Output is correct |
14 |
Correct |
2 ms |
624 KB |
Output is correct |
15 |
Correct |
2 ms |
624 KB |
Output is correct |
16 |
Correct |
15 ms |
1060 KB |
Output is correct |
17 |
Correct |
15 ms |
1060 KB |
Output is correct |
18 |
Correct |
15 ms |
1060 KB |
Output is correct |
19 |
Correct |
15 ms |
1060 KB |
Output is correct |
20 |
Correct |
11 ms |
1060 KB |
Output is correct |
21 |
Correct |
54 ms |
2140 KB |
Output is correct |
22 |
Correct |
58 ms |
2140 KB |
Output is correct |
23 |
Correct |
55 ms |
2140 KB |
Output is correct |
24 |
Correct |
55 ms |
2140 KB |
Output is correct |
25 |
Correct |
46 ms |
2140 KB |
Output is correct |
26 |
Correct |
55 ms |
2140 KB |
Output is correct |
27 |
Correct |
59 ms |
2140 KB |
Output is correct |
28 |
Correct |
55 ms |
2140 KB |
Output is correct |
29 |
Correct |
56 ms |
2140 KB |
Output is correct |
30 |
Correct |
42 ms |
2140 KB |
Output is correct |
31 |
Correct |
2 ms |
2140 KB |
Output is correct |
32 |
Correct |
1 ms |
2140 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
2140 KB |
Output isn't correct |
2 |
Incorrect |
2 ms |
2140 KB |
Output isn't correct |
3 |
Incorrect |
2 ms |
2140 KB |
Output isn't correct |
4 |
Incorrect |
2 ms |
2140 KB |
Output isn't correct |
5 |
Incorrect |
2 ms |
2140 KB |
Output isn't correct |
6 |
Incorrect |
2 ms |
2140 KB |
Output isn't correct |
7 |
Incorrect |
1 ms |
2140 KB |
Output isn't correct |
8 |
Incorrect |
1 ms |
2140 KB |
Output isn't correct |
9 |
Incorrect |
1 ms |
2140 KB |
Output isn't correct |
10 |
Incorrect |
2 ms |
2140 KB |
Output isn't correct |
11 |
Incorrect |
2 ms |
2140 KB |
Output isn't correct |
12 |
Incorrect |
2 ms |
2140 KB |
Output isn't correct |
13 |
Incorrect |
2 ms |
2140 KB |
Output isn't correct |
14 |
Incorrect |
2 ms |
2140 KB |
Output isn't correct |
15 |
Incorrect |
2 ms |
2140 KB |
Output isn't correct |
16 |
Incorrect |
8 ms |
2140 KB |
Output isn't correct |
17 |
Incorrect |
9 ms |
2140 KB |
Output isn't correct |
18 |
Incorrect |
9 ms |
2140 KB |
Output isn't correct |
19 |
Incorrect |
9 ms |
2140 KB |
Output isn't correct |
20 |
Incorrect |
5 ms |
2140 KB |
Output isn't correct |
21 |
Incorrect |
29 ms |
2140 KB |
Output isn't correct |
22 |
Incorrect |
30 ms |
2140 KB |
Output isn't correct |
23 |
Incorrect |
29 ms |
2140 KB |
Output isn't correct |
24 |
Incorrect |
30 ms |
2140 KB |
Output isn't correct |
25 |
Incorrect |
22 ms |
2140 KB |
Output isn't correct |
26 |
Incorrect |
29 ms |
2140 KB |
Output isn't correct |
27 |
Incorrect |
29 ms |
2140 KB |
Output isn't correct |
28 |
Incorrect |
31 ms |
2140 KB |
Output isn't correct |
29 |
Incorrect |
39 ms |
2140 KB |
Output isn't correct |
30 |
Incorrect |
15 ms |
2140 KB |
Output isn't correct |
31 |
Incorrect |
2 ms |
2140 KB |
Output isn't correct |
32 |
Incorrect |
2 ms |
2140 KB |
Output isn't correct |