# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
321106 |
2020-11-11T01:02:15 Z |
MetB |
Gap (APIO16_gap) |
C++14 |
|
84 ms |
2052 KB |
#include "gap.h"
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
ll findSmall(int N) {
vector <ll> v (N);
ll mn, mx;
MinMax (1, 1e18, &mn, &mx);
ll s = mn, e = mx;
v[0] = s, v[N-1] = e;
int l = 0, r = N - 1;
while (l + 1 < r) {
MinMax(v[l] + 1, v[r] - 1, &s, &e);
v[++l] = s, v[--r] = e;
}
for (int i = 1; i < N; i++) {
v[i-1] = v[i] - v[i-1];
}
return *max_element(v.begin(), v.end() - 1);
}
ll findGap(int T, int N) {
if (T == 1) {
return findSmall(N);
}
ll mn, mx;
MinMax (1, 1e18, &mn, &mx);
ll s = mn, e = mx;
ld d = (ld) (mx - mn - 2) / N;
ld l = mn + 1, r = mn + 1 + d;
ll gap = 0, mx_old = mn;
for (int i = 0; i < N - 1; i++) {
ll il = ceil (l - 1e-7) + (ceil (l - 1e-7) == mx_old), ir = floor (r + 1e-7);
//cout << il << ' ' << ir << endl;
if (il > ir) continue;
MinMax(il, ir, &mn, &mx);
//cout << ' ' << mn << ' ' << mx << endl;
if (mn != -1) {
gap = max (gap, mn - mx_old);
mx_old = mx;
}
l += d, r += d;
}
ll il = ceil (l - 1e-7) + (ceil (l + 1e-7) == mx_old), ir = floor (r + 1e-7);
//cout << il << ' ' << ir << endl;
if (il <= ir) MinMax(il, ir, &mn, &mx);
//cout << ' ' << mn << ' ' << mx << endl;
if (mn != -1 && il <= ir) {
gap = max (gap, mn - mx_old);
mx_old = mx;
}
gap = max (gap, e - mx_old);
return gap;
}
Compilation message
gap.cpp: In function 'll findGap(int, int)':
gap.cpp:44:5: warning: unused variable 's' [-Wunused-variable]
44 | ll s = mn, e = mx;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
6 |
Correct |
0 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
0 ms |
364 KB |
Output is correct |
9 |
Correct |
0 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
11 ms |
748 KB |
Output is correct |
17 |
Correct |
12 ms |
748 KB |
Output is correct |
18 |
Correct |
11 ms |
748 KB |
Output is correct |
19 |
Correct |
11 ms |
800 KB |
Output is correct |
20 |
Correct |
9 ms |
704 KB |
Output is correct |
21 |
Correct |
46 ms |
1900 KB |
Output is correct |
22 |
Correct |
45 ms |
1900 KB |
Output is correct |
23 |
Correct |
45 ms |
1896 KB |
Output is correct |
24 |
Correct |
45 ms |
1892 KB |
Output is correct |
25 |
Correct |
40 ms |
1872 KB |
Output is correct |
26 |
Correct |
46 ms |
2052 KB |
Output is correct |
27 |
Correct |
46 ms |
2024 KB |
Output is correct |
28 |
Correct |
47 ms |
1932 KB |
Output is correct |
29 |
Correct |
46 ms |
1892 KB |
Output is correct |
30 |
Correct |
38 ms |
1900 KB |
Output is correct |
31 |
Correct |
1 ms |
364 KB |
Output is correct |
32 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
0 ms |
364 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
6 |
Correct |
0 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
0 ms |
364 KB |
Output is correct |
10 |
Correct |
0 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
21 ms |
616 KB |
Output is correct |
17 |
Correct |
21 ms |
492 KB |
Output is correct |
18 |
Correct |
21 ms |
492 KB |
Output is correct |
19 |
Correct |
21 ms |
492 KB |
Output is correct |
20 |
Correct |
12 ms |
492 KB |
Output is correct |
21 |
Correct |
84 ms |
1124 KB |
Output is correct |
22 |
Correct |
84 ms |
1124 KB |
Output is correct |
23 |
Correct |
84 ms |
1124 KB |
Output is correct |
24 |
Correct |
79 ms |
1168 KB |
Output is correct |
25 |
Correct |
79 ms |
1124 KB |
Output is correct |
26 |
Correct |
79 ms |
1200 KB |
Output is correct |
27 |
Correct |
84 ms |
1124 KB |
Output is correct |
28 |
Correct |
78 ms |
1124 KB |
Output is correct |
29 |
Correct |
81 ms |
1252 KB |
Output is correct |
30 |
Correct |
52 ms |
1132 KB |
Output is correct |
31 |
Correct |
1 ms |
364 KB |
Output is correct |
32 |
Correct |
1 ms |
364 KB |
Output is correct |