# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
842305 |
2023-09-02T18:17:44 Z |
popovicirobert |
Gap (APIO16_gap) |
C++14 |
|
47 ms |
3628 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);
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 |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
0 ms |
2392 KB |
Output is correct |
4 |
Correct |
1 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 |
0 ms |
2392 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 |
7 ms |
2900 KB |
Output is correct |
17 |
Correct |
7 ms |
2752 KB |
Output is correct |
18 |
Correct |
7 ms |
2588 KB |
Output is correct |
19 |
Correct |
7 ms |
2584 KB |
Output is correct |
20 |
Correct |
6 ms |
2604 KB |
Output is correct |
21 |
Correct |
28 ms |
3624 KB |
Output is correct |
22 |
Correct |
31 ms |
3628 KB |
Output is correct |
23 |
Correct |
28 ms |
3620 KB |
Output is correct |
24 |
Correct |
28 ms |
3620 KB |
Output is correct |
25 |
Correct |
25 ms |
3624 KB |
Output is correct |
26 |
Correct |
29 ms |
3604 KB |
Output is correct |
27 |
Correct |
32 ms |
3528 KB |
Output is correct |
28 |
Correct |
28 ms |
3620 KB |
Output is correct |
29 |
Correct |
27 ms |
3624 KB |
Output is correct |
30 |
Correct |
23 ms |
3620 KB |
Output is correct |
31 |
Correct |
0 ms |
2392 KB |
Output is correct |
32 |
Correct |
0 ms |
2392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
2392 KB |
Output is correct |
2 |
Partially correct |
0 ms |
2392 KB |
Partially correct |
3 |
Partially correct |
1 ms |
2392 KB |
Partially correct |
4 |
Partially correct |
0 ms |
2392 KB |
Partially correct |
5 |
Correct |
1 ms |
2392 KB |
Output is correct |
6 |
Partially correct |
0 ms |
2392 KB |
Partially correct |
7 |
Partially correct |
1 ms |
2392 KB |
Partially correct |
8 |
Partially correct |
0 ms |
2392 KB |
Partially correct |
9 |
Partially correct |
0 ms |
2392 KB |
Partially correct |
10 |
Partially correct |
1 ms |
2392 KB |
Partially correct |
11 |
Partially correct |
1 ms |
2392 KB |
Partially correct |
12 |
Partially correct |
1 ms |
2392 KB |
Partially correct |
13 |
Partially correct |
1 ms |
2392 KB |
Partially correct |
14 |
Partially correct |
1 ms |
2392 KB |
Partially correct |
15 |
Correct |
1 ms |
2392 KB |
Output is correct |
16 |
Partially correct |
10 ms |
2672 KB |
Partially correct |
17 |
Partially correct |
11 ms |
2584 KB |
Partially correct |
18 |
Partially correct |
11 ms |
2392 KB |
Partially correct |
19 |
Partially correct |
11 ms |
2592 KB |
Partially correct |
20 |
Correct |
5 ms |
2568 KB |
Output is correct |
21 |
Partially correct |
43 ms |
2772 KB |
Partially correct |
22 |
Partially correct |
42 ms |
2856 KB |
Partially correct |
23 |
Partially correct |
42 ms |
2852 KB |
Partially correct |
24 |
Partially correct |
47 ms |
3104 KB |
Partially correct |
25 |
Correct |
37 ms |
2848 KB |
Output is correct |
26 |
Partially correct |
43 ms |
3108 KB |
Partially correct |
27 |
Partially correct |
42 ms |
2864 KB |
Partially correct |
28 |
Partially correct |
45 ms |
2860 KB |
Partially correct |
29 |
Partially correct |
47 ms |
3112 KB |
Partially correct |
30 |
Correct |
21 ms |
2848 KB |
Output is correct |
31 |
Partially correct |
1 ms |
2392 KB |
Partially correct |
32 |
Partially correct |
0 ms |
2392 KB |
Partially correct |