#include <bits/stdc++.h>
#include "gap.h"
#define ad push_back
#define lli long long int
using namespace std;
int n;
lli l, r;
long long findGap(int T, int N)
{
n = N;
lli nl, nr;
MinMax(0, 1e18, &nl, &nr);
if(T == 1 || N <= 8)
{
vector <lli> a, b;
a.ad(nl), b.ad(nr);
for (int i = 0; i < (n - 1) / 2; i++)
{
MinMax(nl + 1, nr - 1, &nl, &nr);
a.ad(nl), b.ad(nr);
}
lli mx = 0;
reverse(b.begin(), b.end());
for(auto p : b) a.ad(p);
for (int i = 0; i < a.size() - 1; i++)
mx = max(mx, a[i + 1] - a[i]);
return mx;
}
lli ans = (nr - nl - 2LL) / (n - 1LL) + 1LL;
while(nl < nr - ans)
{
MinMax(nl + 1, nl + ans + 1LL, &l, &r);
if(l == -1)
{
ans += 2LL;
while(l == -1)
{
MinMax(nl + 1LL, nl + ans * 2, &l, &r);
if(l == -1) ans *= 2LL, ans++;
else ans = max(ans, l - nl), nl = r;
}
}
else ans = max(ans, l - nl), nl = r;
}
return ans;
}
Compilation message
gap.cpp: In function 'long long int findGap(int, int)':
gap.cpp:26:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
26 | for (int i = 0; i < a.size() - 1; i++)
| ~~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
15 ms |
1024 KB |
Output is correct |
17 |
Correct |
14 ms |
1024 KB |
Output is correct |
18 |
Correct |
14 ms |
1152 KB |
Output is correct |
19 |
Correct |
13 ms |
1024 KB |
Output is correct |
20 |
Correct |
9 ms |
1024 KB |
Output is correct |
21 |
Correct |
54 ms |
2716 KB |
Output is correct |
22 |
Correct |
53 ms |
2712 KB |
Output is correct |
23 |
Correct |
53 ms |
2716 KB |
Output is correct |
24 |
Correct |
53 ms |
2716 KB |
Output is correct |
25 |
Correct |
46 ms |
2716 KB |
Output is correct |
26 |
Correct |
57 ms |
2676 KB |
Output is correct |
27 |
Correct |
60 ms |
2804 KB |
Output is correct |
28 |
Correct |
53 ms |
2728 KB |
Output is correct |
29 |
Correct |
53 ms |
2716 KB |
Output is correct |
30 |
Correct |
39 ms |
2800 KB |
Output is correct |
31 |
Correct |
0 ms |
384 KB |
Output is correct |
32 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
10 ms |
512 KB |
Output is correct |
17 |
Correct |
9 ms |
512 KB |
Output is correct |
18 |
Correct |
10 ms |
512 KB |
Output is correct |
19 |
Correct |
10 ms |
512 KB |
Output is correct |
20 |
Correct |
4 ms |
512 KB |
Output is correct |
21 |
Correct |
36 ms |
1148 KB |
Output is correct |
22 |
Correct |
37 ms |
1144 KB |
Output is correct |
23 |
Correct |
37 ms |
1060 KB |
Output is correct |
24 |
Correct |
40 ms |
1144 KB |
Output is correct |
25 |
Correct |
60 ms |
1144 KB |
Output is correct |
26 |
Correct |
37 ms |
1128 KB |
Output is correct |
27 |
Correct |
38 ms |
1144 KB |
Output is correct |
28 |
Correct |
45 ms |
1144 KB |
Output is correct |
29 |
Correct |
36 ms |
1144 KB |
Output is correct |
30 |
Correct |
23 ms |
1152 KB |
Output is correct |
31 |
Correct |
0 ms |
384 KB |
Output is correct |
32 |
Correct |
0 ms |
384 KB |
Output is correct |