#include "gap.h"
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include <debug.h>
#include "grader.cpp"
#endif
#define st first
#define nd second
#define pb push_back
#define pf push_front
#define _pb pop_back
#define _pf pop_front
#define lb lower_bound
#define ub upper_bound
#define mtp make_tuple
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
typedef long long ll; typedef unsigned long long ull;
typedef double db; typedef long double ldb;
typedef pair<int, int> pi; typedef pair<ll, ll> pll;
typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pi> vpi; typedef vector<pll> vpll;
typedef string str;
template<typename T> T gcd(T a, T b) { return (b == 0? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
#define FOS(i, r, l) for (int (i) = (r); (i) >= (l); --(i))
#define EACH(i, x) for (auto &(i) : (x))
#define WHILE while
#define file "TEST"
mt19937 rd(chrono::steady_clock::now().time_since_epoch().count());
ll rand(ll l, ll r) { return uniform_int_distribution<ll>(l, r)(rd); }
/*
Tran The Bao
CTL - Da Lat
Cay ngay cay dem nhung deo duoc cong nhan
*/
const int NMAX = 1e5 + 1;
int n;
ll a[NMAX];
ll findGap(int T, int N) {
::n = N;
if (T == 1) {
ll l = 0, r = 1e18;
int pl = 1, pr = n;
WHILE(pl <= pr) {
MinMax(l, r, &l, &r);
a[pl] = l;
a[pr] = r;
++l;
--r;
++pl;
--pr;
}
ll rs = 0;
FOR(i, 1, n - 1) rs = max(rs, a[i + 1] - a[i]);
return rs;
}
ll l = 0, r = 1e18;
MinMax(l, r, &l, &r);
ll Min = (r - l + n - 2) / (n - 1);
assert((r - l + 1) / (Min + 1) <= n);
ll pre = -1;
ll rs = Min;
for (; l <= r;) {
ll nl = l;
ll nr = min(l + Min, r);
MinMax(nl, nr, &nl, &nr);
if (nl != -1 && pre != -1) rs = max(rs, nl - pre);
if (nr != -1) pre = nr;
l += Min + 1;
}
return rs;
}
Compilation message
gap.cpp: In function 'll findGap(int, int)':
gap.cpp:26:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
26 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
| ^
gap.cpp:56:3: note: in expansion of macro 'FOR'
56 | FOR(i, 1, n - 1) rs = max(rs, a[i + 1] - a[i]);
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
1 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 |
336 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 |
12 ms |
720 KB |
Output is correct |
17 |
Correct |
9 ms |
720 KB |
Output is correct |
18 |
Correct |
9 ms |
696 KB |
Output is correct |
19 |
Correct |
9 ms |
668 KB |
Output is correct |
20 |
Correct |
7 ms |
692 KB |
Output is correct |
21 |
Correct |
48 ms |
1844 KB |
Output is correct |
22 |
Correct |
48 ms |
1864 KB |
Output is correct |
23 |
Correct |
51 ms |
1752 KB |
Output is correct |
24 |
Correct |
42 ms |
1812 KB |
Output is correct |
25 |
Correct |
32 ms |
1860 KB |
Output is correct |
26 |
Correct |
36 ms |
1844 KB |
Output is correct |
27 |
Correct |
34 ms |
1812 KB |
Output is correct |
28 |
Correct |
43 ms |
1852 KB |
Output is correct |
29 |
Correct |
34 ms |
1832 KB |
Output is correct |
30 |
Correct |
27 ms |
1828 KB |
Output is correct |
31 |
Correct |
0 ms |
208 KB |
Output is correct |
32 |
Correct |
0 ms |
208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
1 ms |
208 KB |
Output is correct |
8 |
Correct |
0 ms |
208 KB |
Output is correct |
9 |
Correct |
0 ms |
208 KB |
Output is correct |
10 |
Correct |
1 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 |
11 ms |
464 KB |
Output is correct |
17 |
Correct |
13 ms |
464 KB |
Output is correct |
18 |
Correct |
14 ms |
508 KB |
Output is correct |
19 |
Correct |
12 ms |
464 KB |
Output is correct |
20 |
Correct |
6 ms |
524 KB |
Output is correct |
21 |
Correct |
50 ms |
1000 KB |
Output is correct |
22 |
Correct |
49 ms |
984 KB |
Output is correct |
23 |
Correct |
46 ms |
1072 KB |
Output is correct |
24 |
Correct |
48 ms |
1096 KB |
Output is correct |
25 |
Correct |
49 ms |
1020 KB |
Output is correct |
26 |
Correct |
50 ms |
1000 KB |
Output is correct |
27 |
Correct |
55 ms |
1092 KB |
Output is correct |
28 |
Correct |
47 ms |
968 KB |
Output is correct |
29 |
Correct |
51 ms |
1096 KB |
Output is correct |
30 |
Correct |
27 ms |
1104 KB |
Output is correct |
31 |
Correct |
0 ms |
208 KB |
Output is correct |
32 |
Correct |
0 ms |
208 KB |
Output is correct |