Submission #954765

# Submission time Handle Problem Language Result Execution time Memory
954765 2024-03-28T14:03:24 Z Itamar Gap (APIO16_gap) C++14
Compilation error
0 ms 0 KB
#include "gap.h"
using namespace std;
#define ll long long
#include <vector>
#define vll vector<ll>
#include <algorithm>
long long findGap(int T, int N)
{
	if (T == 1) {
		ll a = -1, b = 1e18 + 1;
		vll v;
		for (int it = 0; it < (N + 1) / 2; it++) {
			auto *at = new ll, *bt = new ll;
			MinMax(a + 1, b - 1, at, bt);
			a = *at, b = *bt;
			v.push_back(a); if(a!=b)v.push_back(b);
		}
		sort(v.begin(), v.end());
		ll ans = 0;
		for (int i = 0; i < v.size() - 1; i++)ans = max(ans, v[i + 1] - v[i]);
		return ans;
	}
	else {
		auto* a = new ll, * b = new  ll;
		MinMax(0, 1e18, a, b);
		vll v;
		ll d = ((* b) - (* a) + N - 2) / (N - 1);
		for (int i = *a; i < *b; i += d + 1) {
			auto *c = new ll, * k = new ll;
			MinMax(i, i+d, c, k);
			v.push_back((ll)*c); v.push_back((ll) * k);
		}
		/*sort(v.begin(), v.end());
		ll ans = d;
		for (int i = 0; i+1 < v.size(); i++) {
			if (v[i] > -1) {
				ans = max(ans, v[i + 1] - v[i]);
			}
		}*/
		return ans;
	}
}

Compilation message

gap.cpp: In function 'long long int findGap(int, int)':
gap.cpp:20:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |   for (int i = 0; i < v.size() - 1; i++)ans = max(ans, v[i + 1] - v[i]);
      |                   ~~^~~~~~~~~~~~~~
gap.cpp:40:10: error: 'ans' was not declared in this scope; did you mean 'abs'?
   40 |   return ans;
      |          ^~~
      |          abs