#include "gap.h"
#include <algorithm>
#include <vector>
using namespace std;
#define ll long long
const ll MAX = 1e18;
const int N = 1e5 + 5;
ll a[N];
long long findGap(int t, int n)
{
ll ans = 1;
if (t == 1) {
ll l = 0, r = MAX;
int x = 0, y = n - 1;
while (x <= y) {
MinMax(l, r, &a[x], &a[y]);
l = a[x] + 1;
r = a[y] - 1;
x++;
y--;
}
for (int i = 0; i < n - 1; i++)
ans = max(ans, a[i + 1] - a[i]);
}
else {
ll L, R, mn, mx, x;
MinMax(0, MAX, &L, &R);
x = (R - L - 1) / (n - 1) + 1;
vector<pair<ll, ll>> v;
for (ll i = L; i <= R; i += x + 1) {
MinMax(i, i + x, &mn, &mx);
if (mn != -1) {
v.push_back({ mn, mx });
ans = max(ans, mx - mn);
}
}
for (int i = 1; i < v.size(); i++) {
ans = max(ans, v[i].first - v[i - 1].second);
}
}
return ans;
}
Compilation message
gap.cpp: In function 'long long int findGap(int, int)':
gap.cpp:43:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 1; i < v.size(); i++) {
~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
256 KB |
Output is correct |
11 |
Correct |
3 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
3 ms |
384 KB |
Output is correct |
16 |
Correct |
13 ms |
740 KB |
Output is correct |
17 |
Correct |
12 ms |
768 KB |
Output is correct |
18 |
Correct |
13 ms |
768 KB |
Output is correct |
19 |
Correct |
13 ms |
768 KB |
Output is correct |
20 |
Correct |
9 ms |
768 KB |
Output is correct |
21 |
Correct |
45 ms |
1912 KB |
Output is correct |
22 |
Correct |
49 ms |
1876 KB |
Output is correct |
23 |
Correct |
45 ms |
1884 KB |
Output is correct |
24 |
Correct |
53 ms |
1912 KB |
Output is correct |
25 |
Correct |
39 ms |
1912 KB |
Output is correct |
26 |
Correct |
54 ms |
1912 KB |
Output is correct |
27 |
Correct |
50 ms |
1928 KB |
Output is correct |
28 |
Correct |
64 ms |
1912 KB |
Output is correct |
29 |
Correct |
50 ms |
1912 KB |
Output is correct |
30 |
Correct |
37 ms |
1912 KB |
Output is correct |
31 |
Correct |
3 ms |
384 KB |
Output is correct |
32 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
3 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
384 KB |
Output is correct |
13 |
Correct |
3 ms |
384 KB |
Output is correct |
14 |
Correct |
3 ms |
384 KB |
Output is correct |
15 |
Correct |
3 ms |
384 KB |
Output is correct |
16 |
Correct |
18 ms |
896 KB |
Output is correct |
17 |
Correct |
17 ms |
896 KB |
Output is correct |
18 |
Correct |
19 ms |
896 KB |
Output is correct |
19 |
Correct |
22 ms |
896 KB |
Output is correct |
20 |
Correct |
10 ms |
628 KB |
Output is correct |
21 |
Correct |
64 ms |
2288 KB |
Output is correct |
22 |
Correct |
70 ms |
2288 KB |
Output is correct |
23 |
Correct |
71 ms |
2416 KB |
Output is correct |
24 |
Correct |
73 ms |
2416 KB |
Output is correct |
25 |
Correct |
74 ms |
3304 KB |
Output is correct |
26 |
Correct |
69 ms |
2288 KB |
Output is correct |
27 |
Correct |
74 ms |
2336 KB |
Output is correct |
28 |
Correct |
77 ms |
2296 KB |
Output is correct |
29 |
Correct |
70 ms |
2288 KB |
Output is correct |
30 |
Correct |
36 ms |
1528 KB |
Output is correct |
31 |
Correct |
2 ms |
384 KB |
Output is correct |
32 |
Correct |
3 ms |
384 KB |
Output is correct |