Submission #1018953

#TimeUsernameProblemLanguageResultExecution timeMemory
1018953coolboy19521Gap (APIO16_gap)C++17
30 / 100
58 ms2360 KiB
#include "bits/stdc++.h" #include "gap.h" using namespace std; const int sz = 1e5 + 5; long long a[sz]; long long findGap(int T, int N) { if (1 == T) { long long mn, mx; MinMax(0, 1e18, &mn, &mx); a[1] = mn; a[N] = mx; for (int i = 1; i <= (N+1)/2-1; i ++) { MinMax(mn+1, mx-1, &mn, &mx); a[i+1] = mn; a[N - i] = mx; } long long gp = 0; for (int i = 1; i <= N-1; i ++) gp = max(gp, a[i+1] - a[i]); return gp; } if (T == 2) { long long mn, mx; MinMax(0, 1e18, &mn, &mx); vector<long long> b = {mn, mx}; long long k = (mx - mn) / (N - 1); while (b.size() < N) { long long nextMin, nextMax; long long rangeStart = mn + 1; long long rangeEnd = min(mx - 1, mn + k); if (rangeStart > rangeEnd) break; MinMax(rangeStart, rangeEnd, &nextMin, &nextMax); if (nextMin == -1) { // No numbers found in the range mn = rangeEnd + 1; continue; } int tmNM = nextMax; b.push_back(nextMin); if (nextMin != nextMax) { b.push_back(nextMax); while (nextMin < nextMax && b.size() < N) { // Keep querying within the narrowed range if (nextMin+1>nextMax-1)break; MinMax(nextMin + 1, nextMax - 1, &nextMin, &nextMax); if (nextMin == -1) break; // Exit if no more numbers are found if (nextMin == nextMax) { b.push_back(nextMin); break; } else { b.push_back(nextMin); b.push_back(nextMax); } } } mn = tmNM + 1; // Move to the next range beyond the last found max } // Sorting the elements to find the maximum gap sort(begin(b), end(b)); // for (int x : b) // cout << x << ' '; //cout << '\n'; long long maxGap = 0; for (int i = 0; i < b.size() - 1; i++) { maxGap = max(maxGap, b[i + 1] - b[i]); } return maxGap; } return 0; // This part should never be reached for T = 2 }

Compilation message (stderr)

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