# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
842309 |
2023-09-02T18:19:45 Z |
popovicirobert |
Gap (APIO16_gap) |
C++14 |
|
37 ms |
3876 KB |
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
using ull = unsigned long long;
using ll = long long;
using namespace std;
constexpr ll INF = 1e18;
vector<ll> arr;
#ifdef HOME
void MinMax(ll a, ll b, ll* mn, ll* mx) {
*mn = INF;
*mx = -INF;
for (auto itr : arr) {
if (itr >= a && itr <= b) {
*mn = min(*mn, itr);
*mx = max(*mx, itr);
}
}
if (*mn == INF) {
*mn = -1;
}
if (*mx == -INF) {
*mx = -1;
}
}
#else
#include "gap.h"
#endif
pair<ll, ll> Query(ll a, ll b) {
ll mn, mx;
MinMax(a, b, &mn, &mx);
return {mn, mx};
}
ll findGap1(int N) {
vector<ll> a(N + 2);
a[0] = -1, a[N + 1] = INF + 1;
int left = 1, right = N;
while (left <= right) {
pair<ll, ll> res = Query(a[left - 1] + 1, a[right + 1] - 1);
a[left] = res.first;
a[right] = res.second;
left++, right--;
}
ll answer = 0;
for (int i = 1; i < N; i++) {
answer = max(answer, a[i + 1] - a[i]);
}
return answer;
}
ll findGap2(int N) {
pair<ll, ll> res = Query(0, INF);
ll a1 = res.first;
ll an = res.second;
ll step = (an - a1 + N - 2) / (N - 1);
ll answer = 0;
ll curr = a1;
while (curr < an) {
int x = 0;
do {
x++;
res = Query(curr + 1, curr + step * x);
if (res.second != -1) {
break;
}
} while (true);
answer = max(answer, res.first - curr);
step = max(step, answer);
curr = res.second;
}
return answer;
}
ll findGap(int T, int N) {
return T == 1 ? findGap1(N) : findGap2(N);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
2392 KB |
Output is correct |
3 |
Correct |
0 ms |
2392 KB |
Output is correct |
4 |
Correct |
0 ms |
2392 KB |
Output is correct |
5 |
Correct |
0 ms |
2644 KB |
Output is correct |
6 |
Correct |
0 ms |
2392 KB |
Output is correct |
7 |
Correct |
0 ms |
2644 KB |
Output is correct |
8 |
Correct |
0 ms |
2392 KB |
Output is correct |
9 |
Correct |
0 ms |
2392 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2392 KB |
Output is correct |
12 |
Correct |
1 ms |
2392 KB |
Output is correct |
13 |
Correct |
1 ms |
2392 KB |
Output is correct |
14 |
Correct |
1 ms |
2392 KB |
Output is correct |
15 |
Correct |
1 ms |
2392 KB |
Output is correct |
16 |
Correct |
8 ms |
2584 KB |
Output is correct |
17 |
Correct |
8 ms |
2648 KB |
Output is correct |
18 |
Correct |
7 ms |
2592 KB |
Output is correct |
19 |
Correct |
7 ms |
2592 KB |
Output is correct |
20 |
Correct |
6 ms |
2572 KB |
Output is correct |
21 |
Correct |
28 ms |
3620 KB |
Output is correct |
22 |
Correct |
30 ms |
3624 KB |
Output is correct |
23 |
Correct |
28 ms |
3624 KB |
Output is correct |
24 |
Correct |
33 ms |
3624 KB |
Output is correct |
25 |
Correct |
25 ms |
3780 KB |
Output is correct |
26 |
Correct |
28 ms |
3624 KB |
Output is correct |
27 |
Correct |
30 ms |
3876 KB |
Output is correct |
28 |
Correct |
28 ms |
3624 KB |
Output is correct |
29 |
Correct |
34 ms |
3624 KB |
Output is correct |
30 |
Correct |
23 ms |
3628 KB |
Output is correct |
31 |
Correct |
1 ms |
2392 KB |
Output is correct |
32 |
Correct |
0 ms |
2588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
0 ms |
2392 KB |
Output is correct |
5 |
Correct |
1 ms |
2392 KB |
Output is correct |
6 |
Correct |
1 ms |
2392 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2392 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
10 |
Correct |
0 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2392 KB |
Output is correct |
12 |
Correct |
1 ms |
2392 KB |
Output is correct |
13 |
Correct |
1 ms |
2392 KB |
Output is correct |
14 |
Correct |
1 ms |
2392 KB |
Output is correct |
15 |
Correct |
1 ms |
2392 KB |
Output is correct |
16 |
Correct |
5 ms |
2752 KB |
Output is correct |
17 |
Correct |
5 ms |
2588 KB |
Output is correct |
18 |
Correct |
4 ms |
2752 KB |
Output is correct |
19 |
Correct |
5 ms |
2580 KB |
Output is correct |
20 |
Correct |
3 ms |
2572 KB |
Output is correct |
21 |
Correct |
17 ms |
2856 KB |
Output is correct |
22 |
Correct |
17 ms |
2852 KB |
Output is correct |
23 |
Correct |
18 ms |
3104 KB |
Output is correct |
24 |
Correct |
17 ms |
2784 KB |
Output is correct |
25 |
Correct |
37 ms |
2848 KB |
Output is correct |
26 |
Correct |
18 ms |
2648 KB |
Output is correct |
27 |
Correct |
18 ms |
2852 KB |
Output is correct |
28 |
Correct |
17 ms |
2856 KB |
Output is correct |
29 |
Correct |
17 ms |
2856 KB |
Output is correct |
30 |
Correct |
14 ms |
2852 KB |
Output is correct |
31 |
Correct |
1 ms |
2392 KB |
Output is correct |
32 |
Correct |
0 ms |
2392 KB |
Output is correct |