#include "gap.h"
#include <vector>
#include <iostream>
#include <random>
#include <algorithm>
#include <tuple>
using namespace std;
const long long INF = 1e18;
mt19937_64 rnd(23478612);
inline long long random(long long MIN, long long MAX) {
return rnd() % (MAX - MIN + 1) + MIN;
}
long long calc_cost(const vector<long long> &seq) {
long long res = 0;
for (int i = 0; i + 1 < (int)seq.size(); i++)
res = max(res, seq[i + 1] - seq[i]);
return res;
}
namespace SUB1 {
long long findGap(int N) {
vector<long long> seq(N);
long long L = 0, R = INF;
for (int i = 0, j = N - 1; i <= j; i++, j--) {
MinMax(L, R, &seq[i], &seq[j]);
L = seq[i] + 1, R = seq[j] - 1;
}
return calc_cost(seq);
}
}
namespace SUB2 {
long long findGap(int N) {
long long MIN, MAX;
MinMax(0, INF, &MIN, &MAX);
if (N == 2)
return MAX - MIN;
long long d = (MAX - MIN + 1 + N - 3) / (N - 2LL);
vector<pair<long long, long long>> rep;
for (long long l = MIN, r = MIN + d - 1; ; l += d, r += d) {
long long rep_l, rep_r;
MinMax(l, min(r, MAX), &rep_l, &rep_r);
if (rep_l == -1) continue;
rep.emplace_back(rep_l, rep_r);
if (r >= MAX)
break;
}
long long ans = 0;
for (int i = 0; i + 1 < (int)rep.size(); i++) {
long long l = rep[i].second, r = rep[i + 1].first;
ans = max(ans, r - l);
}
return ans;
}
}
long long findGap(int T, int N) {
return (T == 1) ? SUB1::findGap(N) : SUB2::findGap(N);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
0 ms |
208 KB |
Output is correct |
6 |
Correct |
1 ms |
208 KB |
Output is correct |
7 |
Correct |
1 ms |
256 KB |
Output is correct |
8 |
Correct |
0 ms |
208 KB |
Output is correct |
9 |
Correct |
0 ms |
208 KB |
Output is correct |
10 |
Correct |
0 ms |
208 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
9 ms |
608 KB |
Output is correct |
17 |
Correct |
11 ms |
688 KB |
Output is correct |
18 |
Correct |
12 ms |
644 KB |
Output is correct |
19 |
Correct |
10 ms |
720 KB |
Output is correct |
20 |
Correct |
8 ms |
720 KB |
Output is correct |
21 |
Correct |
45 ms |
1876 KB |
Output is correct |
22 |
Correct |
37 ms |
1784 KB |
Output is correct |
23 |
Correct |
39 ms |
1776 KB |
Output is correct |
24 |
Correct |
38 ms |
1828 KB |
Output is correct |
25 |
Correct |
34 ms |
1788 KB |
Output is correct |
26 |
Correct |
41 ms |
1828 KB |
Output is correct |
27 |
Correct |
38 ms |
1824 KB |
Output is correct |
28 |
Correct |
44 ms |
1824 KB |
Output is correct |
29 |
Correct |
40 ms |
1824 KB |
Output is correct |
30 |
Correct |
32 ms |
1820 KB |
Output is correct |
31 |
Correct |
1 ms |
208 KB |
Output is correct |
32 |
Correct |
0 ms |
208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
0 ms |
208 KB |
Output is correct |
6 |
Correct |
0 ms |
208 KB |
Output is correct |
7 |
Correct |
0 ms |
208 KB |
Output is correct |
8 |
Correct |
0 ms |
208 KB |
Output is correct |
9 |
Correct |
1 ms |
208 KB |
Output is correct |
10 |
Correct |
0 ms |
208 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
15 ms |
848 KB |
Output is correct |
17 |
Correct |
14 ms |
940 KB |
Output is correct |
18 |
Correct |
13 ms |
848 KB |
Output is correct |
19 |
Correct |
13 ms |
848 KB |
Output is correct |
20 |
Correct |
7 ms |
528 KB |
Output is correct |
21 |
Correct |
68 ms |
2212 KB |
Output is correct |
22 |
Correct |
54 ms |
2184 KB |
Output is correct |
23 |
Correct |
50 ms |
2204 KB |
Output is correct |
24 |
Correct |
52 ms |
2204 KB |
Output is correct |
25 |
Correct |
48 ms |
3260 KB |
Output is correct |
26 |
Correct |
57 ms |
2176 KB |
Output is correct |
27 |
Correct |
56 ms |
2220 KB |
Output is correct |
28 |
Correct |
52 ms |
2136 KB |
Output is correct |
29 |
Correct |
58 ms |
2208 KB |
Output is correct |
30 |
Correct |
26 ms |
1476 KB |
Output is correct |
31 |
Correct |
0 ms |
208 KB |
Output is correct |
32 |
Correct |
0 ms |
208 KB |
Output is correct |