#include "gap.h"
#include <bits/stdc++.h>
using namespace std;
vector<long long> vec;
long long a[100005];
long long findGap(int t, int n)
{
if (t==1)
{
long long l=1, r=1e18, ans=0;
for (int i=1; i<=n/2; i++)
{
MinMax(l, r, &a[i], &a[n-i+1]);
l=a[i]+1;
r=a[n-i+1]-1;
}
if (n&1)
MinMax(l, r, &a[n/2+1], &a[n/2+1]);
for (int i=2; i<=n; i++)
ans=max(ans, a[i]-a[i-1]);
return ans;
}
else
{
long long l, r, num, ans=0;
MinMax(1, 1e18, &l, &r);
vec.push_back(l);
vec.push_back(r);
num=(r-l-1)/(n-1)+1;
for (long long i=l+1; i<r; i+=num+1)
{
long long j=min(r-1, i+num), resL, resR;
MinMax(i, j, &resL, &resR);
if (resL!=-1)
vec.push_back(resL);
if (resR!=resL)
vec.push_back(resR);
}
sort(vec.begin(), vec.end());
for (int i=1; i<vec.size(); i++)
ans=max(ans, vec[i]-vec[i-1]);
return ans;
}
}
Compilation message
gap.cpp: In function 'long long int findGap(int, int)':
gap.cpp:40:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
40 | for (int i=1; i<vec.size(); i++)
| ~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
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 |
1 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 |
1 ms |
208 KB |
Output is correct |
8 |
Correct |
1 ms |
208 KB |
Output is correct |
9 |
Correct |
1 ms |
208 KB |
Output is correct |
10 |
Correct |
0 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 |
11 ms |
592 KB |
Output is correct |
17 |
Correct |
10 ms |
592 KB |
Output is correct |
18 |
Correct |
9 ms |
592 KB |
Output is correct |
19 |
Correct |
9 ms |
720 KB |
Output is correct |
20 |
Correct |
8 ms |
624 KB |
Output is correct |
21 |
Correct |
42 ms |
1828 KB |
Output is correct |
22 |
Correct |
37 ms |
1836 KB |
Output is correct |
23 |
Correct |
39 ms |
1840 KB |
Output is correct |
24 |
Correct |
39 ms |
1860 KB |
Output is correct |
25 |
Correct |
32 ms |
1812 KB |
Output is correct |
26 |
Correct |
47 ms |
1864 KB |
Output is correct |
27 |
Correct |
37 ms |
1864 KB |
Output is correct |
28 |
Correct |
38 ms |
1748 KB |
Output is correct |
29 |
Correct |
37 ms |
1844 KB |
Output is correct |
30 |
Correct |
27 ms |
1780 KB |
Output is correct |
31 |
Correct |
0 ms |
208 KB |
Output is correct |
32 |
Correct |
0 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 |
1 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 |
0 ms |
208 KB |
Output is correct |
8 |
Correct |
0 ms |
208 KB |
Output is correct |
9 |
Correct |
1 ms |
208 KB |
Output is correct |
10 |
Correct |
0 ms |
208 KB |
Output is correct |
11 |
Correct |
2 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 |
848 KB |
Output is correct |
17 |
Correct |
12 ms |
848 KB |
Output is correct |
18 |
Correct |
15 ms |
848 KB |
Output is correct |
19 |
Correct |
14 ms |
920 KB |
Output is correct |
20 |
Correct |
6 ms |
464 KB |
Output is correct |
21 |
Correct |
59 ms |
2184 KB |
Output is correct |
22 |
Correct |
59 ms |
2216 KB |
Output is correct |
23 |
Correct |
51 ms |
2156 KB |
Output is correct |
24 |
Correct |
55 ms |
2208 KB |
Output is correct |
25 |
Correct |
53 ms |
2136 KB |
Output is correct |
26 |
Correct |
55 ms |
2212 KB |
Output is correct |
27 |
Correct |
50 ms |
2248 KB |
Output is correct |
28 |
Correct |
55 ms |
2192 KB |
Output is correct |
29 |
Correct |
70 ms |
2328 KB |
Output is correct |
30 |
Correct |
34 ms |
1456 KB |
Output is correct |
31 |
Correct |
0 ms |
208 KB |
Output is correct |
32 |
Correct |
1 ms |
208 KB |
Output is correct |