#include <bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) static_cast<int>((x).size())
template<class T, size_t D>
struct vec : vector<vec<T, D - 1>> {
template<class... Args>
vec(size_t n = 0, Args... args)
: vector<vec<T, D - 1>>(n, vec<T, D - 1>(args...)) {}
};
template<class T>
struct vec<T, 1> : vector<T> {
template<class... Args>
vec(Args... args)
: vector<T>(args...) {}
};
template<class T>
inline bool Minimize(T& a, const T& b) { return a > b ? a = b, true : false; }
template<class T>
inline bool Maximize(T& a, const T& b) { return a < b ? a = b, true : false; }
inline int Next(int i, int n) { return i == n - 1 ? 0 : i + 1; }
inline int Prev(int i, int n) { return !i ? n - 1 : i - 1; }
mt19937 rng(static_cast<uint32_t>(chrono::steady_clock::now().time_since_epoch().count()));
#include "gap.h"
long long findGap(int subtask, int n) {
if (subtask == 1) {
long long min_value, max_value, answer = 0;
vec<long long, 1> a(n);
for (int left_index = 0, right_index = n - 1; left_index <= right_index; ++left_index, --right_index) {
static long long left_value = 0, right_value = static_cast<long long>(1e18);
MinMax(left_value, right_value, &min_value, &max_value);
a[left_index] = min_value;
a[right_index] = max_value;
left_value = min_value + 1;
right_value = max_value - 1;
}
for (int i = 1; i < n; ++i) {
Maximize(answer, a[i] - a[i - 1]);
}
return answer;
} else {
long long min_value, max_value, answer;
MinMax(0, static_cast<long long>(1e18), &min_value, &max_value);
auto max_a = max_value;
auto const magic = (max_value - min_value + n - 2) / (n - 1);
answer = magic;
for (long long left_value = min_value + 1, right_value = min_value + magic, last_value = min_value; left_value <= max_a; left_value += magic, right_value += magic) {
MinMax(left_value, right_value, &min_value, &max_value);
if (~min_value) {
Maximize(answer, min_value - last_value);
last_value = max_value;
}
}
return answer;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
12 ms |
768 KB |
Output is correct |
17 |
Correct |
12 ms |
768 KB |
Output is correct |
18 |
Correct |
13 ms |
768 KB |
Output is correct |
19 |
Correct |
12 ms |
768 KB |
Output is correct |
20 |
Correct |
10 ms |
896 KB |
Output is correct |
21 |
Correct |
50 ms |
1912 KB |
Output is correct |
22 |
Correct |
50 ms |
1912 KB |
Output is correct |
23 |
Correct |
49 ms |
1912 KB |
Output is correct |
24 |
Correct |
52 ms |
1916 KB |
Output is correct |
25 |
Correct |
57 ms |
1920 KB |
Output is correct |
26 |
Correct |
49 ms |
1912 KB |
Output is correct |
27 |
Correct |
58 ms |
1912 KB |
Output is correct |
28 |
Correct |
57 ms |
1912 KB |
Output is correct |
29 |
Correct |
48 ms |
1912 KB |
Output is correct |
30 |
Correct |
34 ms |
1920 KB |
Output is correct |
31 |
Correct |
0 ms |
384 KB |
Output is correct |
32 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
15 ms |
512 KB |
Output is correct |
17 |
Correct |
16 ms |
512 KB |
Output is correct |
18 |
Correct |
15 ms |
512 KB |
Output is correct |
19 |
Correct |
15 ms |
512 KB |
Output is correct |
20 |
Correct |
8 ms |
512 KB |
Output is correct |
21 |
Correct |
64 ms |
1144 KB |
Output is correct |
22 |
Correct |
64 ms |
1116 KB |
Output is correct |
23 |
Correct |
65 ms |
1144 KB |
Output is correct |
24 |
Correct |
65 ms |
1180 KB |
Output is correct |
25 |
Correct |
57 ms |
1152 KB |
Output is correct |
26 |
Correct |
64 ms |
1144 KB |
Output is correct |
27 |
Correct |
72 ms |
1088 KB |
Output is correct |
28 |
Correct |
65 ms |
1148 KB |
Output is correct |
29 |
Correct |
66 ms |
1260 KB |
Output is correct |
30 |
Correct |
34 ms |
1156 KB |
Output is correct |
31 |
Correct |
1 ms |
384 KB |
Output is correct |
32 |
Correct |
0 ms |
384 KB |
Output is correct |