Submission #302847

#TimeUsernameProblemLanguageResultExecution timeMemory
302847arayiGap (APIO16_gap)C++17
100 / 100
60 ms2804 KiB
#include <bits/stdc++.h> #include "gap.h" #define ad push_back #define lli long long int using namespace std; int n; lli l, r; long long findGap(int T, int N) { n = N; lli nl, nr; MinMax(0, 1e18, &nl, &nr); if(T == 1 || N <= 8) { vector <lli> a, b; a.ad(nl), b.ad(nr); for (int i = 0; i < (n - 1) / 2; i++) { MinMax(nl + 1, nr - 1, &nl, &nr); a.ad(nl), b.ad(nr); } lli mx = 0; reverse(b.begin(), b.end()); for(auto p : b) a.ad(p); for (int i = 0; i < a.size() - 1; i++) mx = max(mx, a[i + 1] - a[i]); return mx; } lli ans = (nr - nl - 2LL) / (n - 1LL) + 1LL; while(nl < nr - ans) { MinMax(nl + 1, nl + ans + 1LL, &l, &r); if(l == -1) { ans += 2LL; while(l == -1) { MinMax(nl + 1LL, nl + ans * 2, &l, &r); if(l == -1) ans *= 2LL, ans++; else ans = max(ans, l - nl), nl = r; } } else ans = max(ans, l - nl), nl = r; } return ans; }

Compilation message (stderr)

gap.cpp: In function 'long long int findGap(int, int)':
gap.cpp:26:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |         for (int i = 0; i < a.size() - 1; i++)
      |                         ~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...