Submission #39808

#TimeUsernameProblemLanguageResultExecution timeMemory
3980814kgGap (APIO16_gap)C++11
100 / 100
103 ms9052 KiB
#include "gap.h" #include <set> #define NUM_MAX 1000000000000000000 #define max2(x,y) (x>y?x:y) #define min2(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 < E; s += len) { MinMax(s, min2(s + len - 1, E - 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:21:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if (S.size() == n) break;
                ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...