#include "gap.h"
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
using ll = long long;
long long naive(int N)
{
long long l = 0, r = 1e18, lp = 0, rp = N-1, x=0, y=0, a[100100];
for(int i = 0; lp<=rp; i++) {
MinMax(l, r, &x, &y);
a[lp] = x, a[rp] = y;
l=x+1, r=y-1;
lp++,rp--;
}
ll ans = 0;
for(int i = 1; i < N; i++) {
ans = max(ans, a[i]-a[i-1]);
}
return ans;
}
long long findGap(int T, int N) {
if(T==1) {
return naive(N);
}
ll l = 0, r = 1e18, mn, mx, tl, tr, inc = 0;
MinMax(l, r, &mn, &mx);
ll step = (mx - mn + N - 1) / N;
l = mn, r = mn+step;
ll ans = step;
ll omx = mx;
vector<ll> x;
x.pb(mn);
mn++, mx--;
while (true) {
MinMax(l, r, &tl, &tr);
if (tl != -1) {
x.pb(tl);
x.pb(tr);
inc++;
}
if(tl!=-1)
for (int i = max(1, (int)x.size()-3); i < x.size(); i++) {
if(ans < x[i] - x[i - 1]) {
ans = x[i] - x[i - 1];
}
}
if(mx-tr<ans) break;
if (r == mx)
break;
l = r+1;
r = l+ans+1;
r = min(r, mx);
}
x.pb(omx);
for (int i = 1; i < x.size(); i++) {
if(ans < x[i] - x[i - 1]) {
ans = x[i] - x[i - 1];
}
}
return ans;
}
Compilation message
gap.cpp: In function 'long long int findGap(int, int)':
gap.cpp:42:43: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = max(1, (int)x.size()-3); i < x.size(); i++) {
~~^~~~~~~~~~
gap.cpp:55:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 1; i < x.size(); i++) {
~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
380 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
3 ms |
376 KB |
Output is correct |
12 |
Correct |
3 ms |
376 KB |
Output is correct |
13 |
Correct |
3 ms |
376 KB |
Output is correct |
14 |
Correct |
3 ms |
376 KB |
Output is correct |
15 |
Correct |
3 ms |
376 KB |
Output is correct |
16 |
Correct |
15 ms |
760 KB |
Output is correct |
17 |
Correct |
17 ms |
692 KB |
Output is correct |
18 |
Correct |
15 ms |
760 KB |
Output is correct |
19 |
Correct |
17 ms |
760 KB |
Output is correct |
20 |
Correct |
11 ms |
760 KB |
Output is correct |
21 |
Correct |
68 ms |
1912 KB |
Output is correct |
22 |
Correct |
56 ms |
1912 KB |
Output is correct |
23 |
Correct |
57 ms |
1904 KB |
Output is correct |
24 |
Correct |
57 ms |
1872 KB |
Output is correct |
25 |
Correct |
50 ms |
1876 KB |
Output is correct |
26 |
Correct |
57 ms |
2040 KB |
Output is correct |
27 |
Correct |
60 ms |
2168 KB |
Output is correct |
28 |
Correct |
56 ms |
1884 KB |
Output is correct |
29 |
Correct |
58 ms |
1888 KB |
Output is correct |
30 |
Correct |
82 ms |
1912 KB |
Output is correct |
31 |
Correct |
2 ms |
376 KB |
Output is correct |
32 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
3 ms |
376 KB |
Output is correct |
12 |
Correct |
3 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
380 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
3 ms |
376 KB |
Output is correct |
16 |
Correct |
11 ms |
632 KB |
Output is correct |
17 |
Correct |
11 ms |
632 KB |
Output is correct |
18 |
Correct |
11 ms |
632 KB |
Output is correct |
19 |
Correct |
11 ms |
684 KB |
Output is correct |
20 |
Correct |
6 ms |
504 KB |
Output is correct |
21 |
Correct |
35 ms |
1528 KB |
Output is correct |
22 |
Correct |
36 ms |
1528 KB |
Output is correct |
23 |
Correct |
36 ms |
1528 KB |
Output is correct |
24 |
Correct |
38 ms |
1528 KB |
Output is correct |
25 |
Correct |
75 ms |
3312 KB |
Output is correct |
26 |
Correct |
37 ms |
1528 KB |
Output is correct |
27 |
Correct |
37 ms |
1532 KB |
Output is correct |
28 |
Correct |
39 ms |
1528 KB |
Output is correct |
29 |
Correct |
37 ms |
1528 KB |
Output is correct |
30 |
Correct |
16 ms |
1144 KB |
Output is correct |
31 |
Correct |
2 ms |
376 KB |
Output is correct |
32 |
Correct |
2 ms |
376 KB |
Output is correct |