#include "gap.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
long long findGap(int T, int N)
{
if (T == 1)
{
ll lf = 0, rf = 1e18, mn, mx;
set < ll > st;
int nn = 0;
while(nn < N)
{
MinMax(lf, rf, &mn, &mx);
st.insert(mn);
st.insert(mx);
lf = mn + 1;
rf = mx - 1;
nn += 2;
}
ll ans = 0;
ll last = -1;
for (auto it : st)
{
if (last != -1)
ans = max(ans, it - last);
last = it;
}
return ans;
}
else
{
ll lf = 0, rf = 1e18, mn, mx, dn, dx;
MinMax(lf, rf, &mn, &mx);
if (N == 2)
{
return mx - mn;
}
ll len = (mx - mn - 1) / (N - 1);
if ((mx - mn - 1) % (N - 1) != 0)
len ++;
ll last = mn, ans = 0;
for (int i = 0; i < N; i ++)
{
ll s = i * len + mn + 1, e = (i + 1) * len + mn;
MinMax(s, e, &dn, &dx);
if (dn != -1)
{
ans = max(ans, dn - last);
last = dx;
}
}
ans = max(ans, mx - last);
return ans;;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
0 ms |
208 KB |
Output is correct |
6 |
Correct |
1 ms |
208 KB |
Output is correct |
7 |
Correct |
0 ms |
208 KB |
Output is correct |
8 |
Correct |
0 ms |
208 KB |
Output is correct |
9 |
Correct |
0 ms |
208 KB |
Output is correct |
10 |
Correct |
1 ms |
208 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
13 ms |
1616 KB |
Output is correct |
17 |
Correct |
18 ms |
1572 KB |
Output is correct |
18 |
Correct |
15 ms |
1608 KB |
Output is correct |
19 |
Correct |
14 ms |
1624 KB |
Output is correct |
20 |
Correct |
10 ms |
1616 KB |
Output is correct |
21 |
Correct |
53 ms |
5788 KB |
Output is correct |
22 |
Correct |
53 ms |
5704 KB |
Output is correct |
23 |
Correct |
67 ms |
5684 KB |
Output is correct |
24 |
Correct |
54 ms |
5704 KB |
Output is correct |
25 |
Correct |
50 ms |
5704 KB |
Output is correct |
26 |
Correct |
56 ms |
5668 KB |
Output is correct |
27 |
Correct |
54 ms |
5684 KB |
Output is correct |
28 |
Correct |
55 ms |
5668 KB |
Output is correct |
29 |
Correct |
54 ms |
5744 KB |
Output is correct |
30 |
Correct |
51 ms |
5676 KB |
Output is correct |
31 |
Correct |
1 ms |
208 KB |
Output is correct |
32 |
Correct |
1 ms |
208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
0 ms |
208 KB |
Output is correct |
6 |
Correct |
0 ms |
208 KB |
Output is correct |
7 |
Correct |
1 ms |
208 KB |
Output is correct |
8 |
Correct |
0 ms |
208 KB |
Output is correct |
9 |
Correct |
0 ms |
208 KB |
Output is correct |
10 |
Correct |
0 ms |
208 KB |
Output is correct |
11 |
Correct |
1 ms |
208 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
208 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
13 ms |
432 KB |
Output is correct |
17 |
Correct |
13 ms |
464 KB |
Output is correct |
18 |
Correct |
14 ms |
512 KB |
Output is correct |
19 |
Correct |
12 ms |
520 KB |
Output is correct |
20 |
Correct |
6 ms |
464 KB |
Output is correct |
21 |
Correct |
50 ms |
1060 KB |
Output is correct |
22 |
Correct |
49 ms |
1088 KB |
Output is correct |
23 |
Correct |
48 ms |
1060 KB |
Output is correct |
24 |
Correct |
48 ms |
1056 KB |
Output is correct |
25 |
Correct |
44 ms |
1084 KB |
Output is correct |
26 |
Correct |
58 ms |
1048 KB |
Output is correct |
27 |
Correct |
49 ms |
1060 KB |
Output is correct |
28 |
Correct |
54 ms |
1084 KB |
Output is correct |
29 |
Correct |
56 ms |
1064 KB |
Output is correct |
30 |
Correct |
28 ms |
976 KB |
Output is correct |
31 |
Correct |
0 ms |
208 KB |
Output is correct |
32 |
Correct |
0 ms |
208 KB |
Output is correct |