# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
844820 |
2023-09-06T01:57:39 Z |
dutinmeow |
Gap (APIO16_gap) |
C++17 |
|
0 ms |
0 KB |
#include "gap.h"
#include <bits/stdc++.h>
template<typename T>
bool chmax(T &a, T b) {
if (a >= b)
return false;
a = b;
return true;
}
long long findGap(int t, int n) {
if (t == 1) {
std::vector<long long> a;
a.reserve(n);
long long bl = 0, br = 1e18;
for (int i = 0; i < (n + 1) / 2; i++) {
long long al, ar;
MinMax(bl, br, &al, &ar);
a.push_back(al);
a.push_back(ar);
bl = al + 1, br = ar - 1;
}
if ((int)a.size() > n)
a.pop_back();
std::sort(a.begin(), a.end());
long long r = 0;
for (int i = 1; i < n; i++)
chmax(r, a[i] - a[i - 1]);
return r;
} else {
long long bl, br;
MinMax(1, 1e18, &bl, &br);
long long s = (br - bl - 1) / (n - 1);
long long lb, c = bl, r = s;
for (lb = bl; lb + s < br; lb += s + 1) {
long long nl, nr;
MinMax(lb, lb + s, &nl, &nr);
if (nl != -1 && nr != -1) {
chmax(r, nl - c)
c = nr;
}
}
long long nl, nr;
MinMax(lb, br, &nl, &nr);
if (nl != -1 && nr != -1)
chmax(r, nl - c);
return r;
}
}
Compilation message
gap.cpp: In function 'long long int findGap(int, int)':
gap.cpp:41:21: error: expected ';' before 'c'
41 | chmax(r, nl - c)
| ^
| ;
42 | c = nr;
| ~