Submission #21914

#TimeUsernameProblemLanguageResultExecution timeMemory
21914sampritiGap (APIO16_gap)C++14
0 / 100
89 ms7456 KiB
#include "gap.h"

#include <climits>
#include <vector>

using namespace std;

long long findGap(int T, int N) {
  long long L, R;
  MinMax(0, LLONG_MAX, &L, &R);
  long long diff = (R - L - 1)/(N - 1);

  vector<pair<long long, long long> > cands;
  for(long long x = L + 1; x <= R - 1; x += diff) {
    long long qL, qR;
    MinMax(x, min(x + diff - 1, R - 1), &qL, &qR);
    cands.push_back({qL, qR});
  }

  long long ans = 0;
  for(int i = 0; i < cands.size() - 1; i++) {
    if(cands[i] == make_pair(-1LL, -1LL)) continue;
    if(cands[i + 1] != make_pair(-1LL, -1LL)) continue;
    int j = i + 1;
    while(j < cands.size()) {
      if(cands[j].first != -1) break;
      j++;
    }
    ans = max(ans, cands[j].first - cands[i].second);
  }
  return ans;
}

Compilation message (stderr)

gap.cpp: In function 'long long int findGap(int, int)':
gap.cpp:21:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0; i < cands.size() - 1; i++) {
                    ^
gap.cpp:25:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     while(j < cands.size()) {
             ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...