This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "gap.h"
#include <set>
#define NUM_MAX 1000000000000000000
#define max2(x,y) (x>y?x:y)
using namespace std;
int n;
set<long long> S;
long long f1() {
long long l = 0, r = NUM_MAX;
long long t1, t2, res = 0;
while (l <= r) {
MinMax(l, r, &t1, &t2);
if (t1 < 0) break;
S.insert(l = t1), S.insert(r = t2);
l++, r--;
if (S.size() == n) break;
}
t1 = NUM_MAX;
for (auto i : S) res = max2(res, i - t1), t1 = i;
return res;
}
long long f2() {
long long S, E, len, res, t1, t2, path = NUM_MAX;
MinMax(0, NUM_MAX, &S, &E);
res = len = (E - S) / (n - 1) + ((E - S) % (n - 1) ? 1 : 0);
for (long long s = S; s + len <= E; s += len) {
MinMax(s, s + len - 1, &t1, &t2);
if (t1 < 0) continue;
res = max2(res, t1 - path), path = t2;
} res = max2(res, E - path);
return res;
}
long long findGap(int T, int _n) {
n = _n;
if (T == 1) return f1();
else return f2();
}
Compilation message (stderr)
gap.cpp: In function 'long long int f1()':
gap.cpp:20:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (S.size() == n) break;
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |