Submission #230494

#TimeUsernameProblemLanguageResultExecution timeMemory
230494AlexLuchianovGap (APIO16_gap)C++14
100 / 100
88 ms8936 KiB
#include "gap.h"
#include <vector>
#include <algorithm>
#include <iostream>

using namespace std;

using ll = long long;
ll const inf = 1000000000000000000;

long long findGap(int T, int N)
{
  vector<ll> v;
  if(T == 1){
    long long* from = new long long(0);
    long long* to = new long long(inf);

    for(int i = 0;i < N; i += 2){
      MinMax(*from, *to, from, to);
      if(-1 == *from)
        continue;
      v.push_back(*from);
      v.push_back(*to);
      *from = *from + 1;
      *to = *to - 1;
    }
  } else {
    long long* from = new long long(0);
    long long* to = new long long(inf);

    MinMax(*from, *to, from, to); /// 1 + N
    ll d = (*to - *from) / (N - 1);
    v.push_back(*from);
    v.push_back(*to);

    *from = *from + 1;
    *to = *to - 1;

    while(*from <= *to){
      long long* a = new long long(0);
      long long* b = new long long(0);

      MinMax(*from, *from + d, a, b);
      if(0 <= *a){
        v.push_back(*a);
        v.push_back(*b);
      }
      *from = *from + d + 1;
    }
  }

  sort(v.begin(), v.end());

  ll result = 0;
  for(int i = 1; i < v.size(); i++)
    result = max(result, v[i] - v[i - 1]);
	return result;
}

Compilation message (stderr)

gap.cpp: In function 'long long int findGap(int, int)':
gap.cpp:55:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 1; i < v.size(); i++)
                  ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...