Submission #844819

# Submission time Handle Problem Language Result Execution time Memory
844819 2023-09-06T01:56:23 Z dutinmeow Gap (APIO16_gap) C++17
Compilation error
0 ms 0 KB
#include "gap.h"

#include <bits/stdc++.h>

template<typename T>
bool chmax(T &a, T b) { 
	if (a >= b)
		return false;
	a = b;
	return true;
}

long long findGap(int t, int n) {
	if (t == 1) {
		std::vector<long long> a;
		a.reserve(n);
		long long bl = 0, br = 1e18;
		for (int i = 0; i < (n + 1) / 2; i++) {
			long long al, ar;
			MinMax(bl, br, &al, &ar);
			a.push_back(al);
			a.push_back(ar);
			bl = al + 1, br = ar - 1;
		}
		if (a.size() > n)
			a.pop_back();
		std::sort(a.begin(), a.end());
		long long r = 0;
		for (int i = 1; i < n; i++)
			chmax(r, a[i] - a[i - 1]);
		return r;
	} else {
		long long bl, br;
		MinMax(1, 1e18, &bl, &br);
		long long s = (br - bl - 1) / (n - 1);
		long long lb, r = s;
		for (lb = l; lb + s < r; lb += s + 1) {
			long long nl, nr;
			MinMax(lb, lb + s, &nl, &nr);
			if (nl != -1 && nr != -1) {
				chmax(r, nl - l)
				l = nr;
			}
		} 
		long long nl, nr;
		MinMax(lb, r, &nl, &nr);
		if (nl != -1 && nr != -1) 
			chmax(r, nl - l);
		return r;
	}
}

Compilation message

gap.cpp: In function 'long long int findGap(int, int)':
gap.cpp:25:16: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   25 |   if (a.size() > n)
      |       ~~~~~~~~~^~~
gap.cpp:37:13: error: 'l' was not declared in this scope
   37 |   for (lb = l; lb + s < r; lb += s + 1) {
      |             ^
gap.cpp:48:18: error: 'l' was not declared in this scope; did you mean 'nl'?
   48 |    chmax(r, nl - l);
      |                  ^
      |                  nl