Submission #443027

#TimeUsernameProblemLanguageResultExecution timeMemory
443027hibye1217Gap (APIO16_gap)C++17
100 / 100
64 ms3228 KiB
#ifndef NOTSUBMIT
#include "gap.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#endif

ll arr[100020];

ll findGap(int T, int N){
	if (T == 1){
		ll mn = 0, mx = 1e18;
		int st = 1, ed = N;
		while (st <= ed){
			MinMax(mn, mx, &arr[st], &arr[ed]);
			mn = arr[st]+1; mx = arr[ed]-1;
			st += 1; ed -= 1;
		}
		ll ans = 0;
		for (int i = 1; i < N; i++){
			ans = max(ans, arr[i+1] - arr[i]);
		}
		return ans;
	}
	if (T == 2){
		ll mn = 0, mx = 1e18;
		MinMax(0, 1e18, &mn, &mx);
		vector<ll> v;
		ll gap = (mx-mn + N-2) / (N-1);
		for (int i = 1; i < N; i++){
			ll st = mn + (i-1)*gap;
			ll ed = st+gap - 1;
			ll mnv=0, mxv=0;
			MinMax(st, ed, &mnv, &mxv);
			if (mnv != -1){ v.push_back(mnv); }
			if (mxv != -1){ v.push_back(mxv); }
		}
		v.push_back(mx);
		int vl = v.size();
		ll ans = 0;
		for (int i = 1; i < vl; i++){
			ans = max(ans, v[i] - v[i-1]);
		}
		return ans;
	}
}

Compilation message (stderr)

gap.cpp: In function 'll findGap(int, int)':
gap.cpp:46:1: warning: control reaches end of non-void function [-Wreturn-type]
   46 | }
      | ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...